|
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: Sun Dec 07 22: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.