php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64152 php return wrong string with HEAD Request Method
Submitted: 2013-02-05 10:51 UTC Modified: 2015-04-13 15:23 UTC
Votes:4
Avg. Score:3.5 ± 1.7
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: mmicael at gmail dot com Assigned: mike (profile)
Status: Closed Package: Output Control
PHP Version: 5.4.11 OS: linux
Private report: No CVE-ID: None
 [2013-02-05 10:51 UTC] mmicael at gmail dot com
Description:
------------
When we do a HEAD Request Method in php 5.4, php continue executing script even 
if the output buffer exceed the max output_buffering.

the next ob_start, ob_get_contents always return empty string

In php 5.2 and 5.3, the script die after sending the first output buffer that 
reach  the max output_buffering.

Test script:
---------------
$string = '';
for($i=0;$i<5000;$i++) $string .= '0';

ob_start();
echo "test1";
$content = ob_get_contents();
ob_end_clean();

error_log("1-$content");
echo $string;

ob_start();
echo "test2";
$content .= ob_get_contents();
ob_end_clean();

echo $string;

error_log("2-$content");

Expected result:
----------------
In php 5.2 and 5.3

1-test1

Actual result:
--------------
In php 5.4

1-test1
2-test1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-05 11:00 UTC] mmicael at gmail dot com
Modifiying OS
 [2013-02-05 11:00 UTC] mmicael at gmail dot com
-Operating System: Any +Operating System: linux
 [2013-02-05 11:54 UTC] mmicael at gmail dot com
It seems that the behaviour have change with this commit 

https://github.com/php/php-src/commit/11d24c1593d6617f73d3f290617bd8994182f4dc#

the ouput.c don't care anymore about headers_only
 [2013-02-05 13:16 UTC] yvan at dugwood dot com
Seems to be a duplicate of https://bugs.php.net/bug.php?id=61272
 [2013-02-05 13:26 UTC] mmicael at gmail dot com
It's not the same bug

the other bug have already been integrated in php 5.4.11

my bug only appears with HEAD request_method
 [2013-02-07 14:54 UTC] mike@php.net
I cannot see a bug here, sure execution of the script continues...
 [2013-02-07 14:54 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2013-02-07 14:59 UTC] mmicael at gmail dot com
-Status: Feedback +Status: Open
 [2013-02-07 14:59 UTC] mmicael at gmail dot com
it's only doing a HEAD request_method with curl -I for exemple

in php 5.2 and 5.3, the script is stopped after the echo $string;
in php 5.4, he continue bug the ob_get_contents after the echo $string; return 
empty response
 [2013-02-07 15:03 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2013-02-07 15:03 UTC] mike@php.net
Which SAPI?
Are you sure, you don't see error_log output there?
 [2013-02-07 15:06 UTC] mmicael at gmail dot com
I am using php-fpm
 [2013-02-07 15:06 UTC] mmicael at gmail dot com
-Status: Feedback +Status: Open
 [2013-02-07 15:16 UTC] mike@php.net
Cannot reproduce.

I get no output with php-fpm in the response, but in the error_log.
 [2013-02-07 15:16 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-02-07 15:23 UTC] mmicael at gmail dot com
yes the script continue, but it log 

1-test1
2-test1

as we do a second ob_start ob_get_contents with an echo test2, after the echo 
$string, we should have in the logs

1-test1
2-test1test2
 [2013-02-07 15:45 UTC] mike@php.net
Ha, now I understand ;) Yes, this could be a regression.

php_output_header() checks headers_only and sets PHP_OUTPUT_DISABLED.
This leads to php_output_write() return immediately.
 [2013-02-07 15:45 UTC] mike@php.net
-Status: Not a bug +Status: Open -Assigned To: +Assigned To: mike
 [2013-03-27 14:04 UTC] mmicael at gmail dot com
Hi,

did you find a patch to correct this bug ?

Micael
 [2015-04-13 15:23 UTC] mike@php.net
-Status: Assigned +Status: Closed
 [2015-04-13 15:23 UTC] mike@php.net
Behaviour sanitised in PHP-7. See https://wiki.php.net/rfc/continue_ob
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 08:01:23 2019 UTC