php / php/php-src

Apache virtual() failures with session module

オープン
#17,655 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Extension: session SAPI: apache2handler
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Apache 設定で説明されている session.* 設定を使って virtual() を再現し、その後、SG(headers_sent) と共有グローバルの周辺にある virtual() および session-module のパスを調査する。セッション固有の状態が再利用されているのか、誤って復元されているのかを確認する。virtual() の出力に警告が挿入されなくなり、バイナリコンテンツが完全な状態で維持され、関連する動作がテストされていれば完了とする。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
apache, c, php
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。