|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-12-08 00:22 UTC] dbc334 at gmail dot com
Description:
------------
When I send request to script connection_close.php from web browser (Internet Explorer, Firefox or Opera), it returns only "1". connection_close.php is run on Apache 2.2 web server.
But when I execute this script from other php file via file_get_contents (eg. do_request.php), it returns "12".
Test script:
---------------
file connection_close.php:
<?php
ob_start();
print '1';
header("Connection: close");
header("Content-Length: 1");
ob_end_flush();
flush();
sleep(2);
print '2';
?>
file do_request.php:
<?php
print file_get_contents("http://web_server_path/connection_close.php");
?>
Expected result:
----------------
Executing do_request.php should return "1".
Actual result:
--------------
do_request.php returns "12".
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 16:00:01 2025 UTC |
If you move ob_status() three lines downwards (so it's before ob_end_flush()), you will get warning because headers were sent after some content was flushed (this happens when output_buffering is off, which is PHP's default setting). If you change the value of Content-Length from 1 to 2, browsers will display "12" (which is expected). Even simpler test script: <?php header("Content-Length: 1"); print '12'; flush(); ?> I have run this and original test script on several servers from the browser. They gave the same results as follows: Displayed "1" on the following configurations: PHP 5.3.3 with Apache 2.2.15 (CentOS) PHP 5.3.23 with Apache (unknown version, unknown linux) PHP 5.3.28 with Apache (unknown version, unknown linux) PHP 5.4.17 with Apache 2.2.3 (CentOS) PHP 5.5.11 with Apache 2.4.9 (Win32) PHP 5.5.15 with Apache 2.4.10 (Win32) But it displayed "12" on the following configuration: PHP 5.2.17 with Apache (unknown version, unknown linux) (request returned header Content-Length with the value 2 instead of 1) (I monitored all requests with Fiddler and in all requests browsers got "12" in the body of the request.) Also: if you remove flush(), the value of Content-Length header changes from 1 to 2 and browsers display "12".