|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-09-08 16:12 UTC] zimage at icdsoft dot com
Description:
------------
Output comes in chunks of about 8k and cannot be forced by using flush(), ob_flush() or output_buffering = Off
I've tested with netcat to avoid browser buffering issues:
echo -ne 'GET /buf.php HTTP/1.0\n\n' |nc 10.0.0.1 80
Reproduce code:
---------------
<?php
for ($i=0; $i<4; $i++){
echo "$i\n";
ob_flush();
flush();
sleep (1);
}
?>
Expected result:
----------------
When run under mod_php, cgi version or lighttpd+php/fastcgi there is one digit printed per second.
Actual result:
--------------
When run under apache 1.3.33 + php/fastcgi the entire output is printed at once.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 01:00:01 2025 UTC |
And strace of php process looks like: read(4, "<?php\n\tfor ($i=0; $i<4; $i++){\n\t"..., 8192) = 65 read(4, "", 4096) = 0 read(4, "", 8192) = 0 close(4) = 0 munmap(0x4056b000, 4096) = 0 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 nanosleep({1, 0}, {1, 0}) = 0 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 nanosleep({1, 0}, {1, 0}) = 0 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 nanosleep({1, 0}, {1, 0}) = 0 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 nanosleep({1, 0}, {1, 0}) = 0 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 write(3, "\1\6\0\1\0@\0\0Content-type: text/html\r"..., 96) = 96 I.e. there are 4 calls to sleep and the script output is writen at once. Any pointers to documentation or further tests that I should perform are welcome.It could be also used for writing progress bars. On a random shared hosting server: locate .php |wc -l 25147 locate .php |xargs -n1 -i grep -H -e "flush *(" {} 641 So people are using it for some reason... I can see flush() used in Moveable Type, Word Press, MediaWiki and so on.I have the same problem.. What I did was to send a lot of blank space to fill up the buffer: add_message($id, str_pad('',4096)); That fixed the problem but increases the bandwidth.So, here is a trivial patch, that works... Sent it to internals@lists.php.net Hope, this will close this bug. ? khext.patch Index: sapi/cgi/cgi_main.c =================================================================== RCS file: /repository/php-src/sapi/cgi/cgi_main.c,v retrieving revision 1.271 diff -u -r1.271 cgi_main.c --- sapi/cgi/cgi_main.c 3 Dec 2005 01:27:37 -0000 1.271 +++ sapi/cgi/cgi_main.c 6 Dec 2005 21:58:18 -0000 @@ -264,13 +264,15 @@ static void sapi_cgibin_flush(void *server_context) { - if (!FCGX_IsCGI()) { + int flush_result; + if (!FCGX_IsCGI()) { FCGX_Request *request = (FCGX_Request *) server_context; - if ( + flush_result = FCGX_FFlush(request->out); + if ( #ifndef PHP_WIN32 !parent && #endif - (!request || FCGX_FFlush(request->out) == -1)) { + (!request || flush_result == -1)) { php_handle_aborted_connection(); } return;