php / php/php-src

Apache virtual() failures with session module

Aperta
#17,655 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Extension: session SAPI: apache2handler
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

Description

This is taken from the note in docs: https://www.php.net/manual/en/function.virtual.php#124597

Starting with 7.2 various session related things were changed and it seems part of it is conflicting with virtual(). Calling it you may receive a "PHP Warning: virtual(): Headers already sent. You cannot change the session module's ini settings at this time in ..." although no header was set and virtual() should simply provide static content from a file.

It took half a day to find out that some main session.configuration.php settings (e.g. save_handler, serialize_handler, or save_path) in the Apache config (all levels) are causing this. It seems the settings are regarded as likely to change headers but virtual() is already beyond sending them. Unfortunately the warning is then not only logged to error_log but also part of the content virtual() sends to the client which screws it up - the format of the content like binary image data is no more correct.

If you do not need php's session management you can remove all session.* settings in your apache configuration to avoid the warning. Otherwise a workaround is to switch off E_WARNING before calling virtual().

<?php
$filename = '/data/image.jpg';
$level = error_reporting();
error_reporting($level & ~E_WARNING); 
virtual($filename);
error_reporting($level);
?>

This will be most likely related sharing of globals and will require some restoring of parent globals like. It needs more checking if it's just for SG(headers_sent) or some session globals as well. In general, there are likely more issue with re-using globals in this way so this might probably need some deeper review. I guess it would be still worth to fix the session specific issues and do a bit more testing to see if more generic approach makes sense.

PHP Version

PHP 8.3+

Operating System

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riprodurre virtual() con le impostazioni session.* descritte in una configurazione Apache, quindi esaminare i percorsi di virtual() e session-module attorno a SG(headers_sent) e alle variabili globali condivise. Verificare se lo stato specifico della sessione viene riutilizzato o ripristinato in modo errato. Il lavoro è completato quando l’avviso non viene più inserito nell’output di virtual(), il contenuto binario rimane intatto e il comportamento pertinente è testato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
apache, c, php
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.