# One more critical problem in 5.4

- Thread: https://externals.io/message/57575
- Original archive: https://news-web.php.net/php.internals/57575
- Started by yoram bar haim on 2012-01-30T15:29:11+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #57575 — yoram bar haim — 2012-01-30T15:29:11+00:00

URL: https://externals.io/message/57575#57575

I Debugged the issue described here by lior.
the problem is :
in php_request_shutdown() we call 
     sapi_send_headers() after 
     php_output_deactivate(). 

at this point, 
in main/output.c, 
OG(flags) & PHP_OUTPUT_ACTIVATED is false so
      php_output_write_unbuffered() calls
              php_output_stderr() instead of
              sapi_module handler.

the following patch solves the issue but It might be a wrong solution (because 
other thins are dependent on this order) so I'm not suggesting it as fix.

--- main/main.c.orig    2012-01-30 17:25:44.000000000 +0200
+++ main/main.c 2012-01-30 17:09:05.000000000 +0200
@@ -1738,12 +1738,13 @@
                } else {
                        php_output_end_all(TSRMLS_C);
                }
+               sapi_send_headers(TSRMLS_C); 
                php_output_deactivate(TSRMLS_C);
        } zend_end_try();
 
        /* 4. Send the set HTTP headers (note: This must be done AFTER 
php_output_discard_all() / php_output_end_all() !!) */
        zend_try {
-               sapi_send_headers(TSRMLS_C);
+/*             sapi_send_headers(TSRMLS_C); */
        } zend_end_try();
 
        /* 5. Reset max_execution_time (no longer executing php code after 
response sent) */

---

## #57576 — Dmitry Stogov — 2012-01-30T15:42:11+00:00

URL: https://externals.io/message/57575#57576 · In reply to: #57575

Hi Mike,

I confirm the bug. In case of empty output HTTP headers are sent to 
stdout or stderr instead of FastCGI stream.

To reproduce I configured nginx to use PHP FastCGI server on UNIX 
socket, then launched (sapi/cgi/php-cgi -b /tmp/fcgi-php5) and performed 
several request to empty PHP file. The HTTP headers were printed in 
console running PHP.

[dmitry@tpl2 CGI-DEBUG]$ sapi/cgi/php-cgi -b /tmp/fcgi-php5
X-Powered-By: PHP/5.4.0RC7-dev
Content-type: text/html

X-Powered-By: PHP/5.4.0RC7-dev
Content-type: text/html

I afraid Yoram's patch is too radical and may have side effects.
Mike, could you please think about a safer way of fixing.

Thanks. Dmitry.



> I Debugged the issue described here by lior.
> the problem is :
> in php_request_shutdown() we call
>       sapi_send_headers() after
>       php_output_deactivate().
>
> at this point,
> in main/output.c,
> OG(flags)&  PHP_OUTPUT_ACTIVATED is false so
>        php_output_write_unbuffered() calls
>                php_output_stderr() instead of
>                sapi_module handler.
>
> the following patch solves the issue but It might be a wrong solution (because
> other thins are dependent on this order) so I'm not suggesting it as fix.
>
> --- main/main.c.orig    2012-01-30 17:25:44.000000000 +0200
> +++ main/main.c 2012-01-30 17:09:05.000000000 +0200
> @@ -1738,12 +1738,13 @@
>                  } else {
>                          php_output_end_all(TSRMLS_C);
>                  }
> +               sapi_send_headers(TSRMLS_C);
>                  php_output_deactivate(TSRMLS_C);
>          } zend_end_try();
>
>          /* 4. Send the set HTTP headers (note: This must be done AFTER
> php_output_discard_all() / php_output_end_all() !!) */
>          zend_try {
> -               sapi_send_headers(TSRMLS_C);
> +/*             sapi_send_headers(TSRMLS_C); */
>          } zend_end_try();
>
>          /* 5. Reset max_execution_time (no longer executing php code after
> response sent) */

---

## #57577 — yoram bar haim — 2012-01-30T15:47:33+00:00

URL: https://externals.io/message/57575#57577 · In reply to: #57576

As I sayed, my patch was not suggusted as fix, Dmitry is write about possible 
side effetcs, it was added only to prove that the problem is what we think it 
is.


> Hi Mike,
> 
> I confirm the bug. In case of empty output HTTP headers are sent to
> stdout or stderr instead of FastCGI stream.
> 
> To reproduce I configured nginx to use PHP FastCGI server on UNIX
> socket, then launched (sapi/cgi/php-cgi -b /tmp/fcgi-php5) and performed
> several request to empty PHP file. The HTTP headers were printed in
> console running PHP.
> 
> [dmitry@tpl2 CGI-DEBUG]$ sapi/cgi/php-cgi -b /tmp/fcgi-php5
> X-Powered-By: PHP/5.4.0RC7-dev
> Content-type: text/html
> 
> X-Powered-By: PHP/5.4.0RC7-dev
> Content-type: text/html
> 
> I afraid Yoram's patch is too radical and may have side effects.
> Mike, could you please think about a safer way of fixing.
> 
> Thanks. Dmitry.
> 
> 
> > […]
