Reply to Re: Unbuffer output in PHP

Your name:

Reply:


Posted by tim on 05/20/06 15:32

Bart Van der Donck wrote:
> Hello,
>
> My Apache is configured so that it times out after ca. 2 and a half
> minutes. For example, the following CGI script would have a time out
> (because it runs longer than 2:30):
>
> #!/usr/bin/perl
> print "Content-Type: text/html\n\n";
> for (0..1000) {
> print "seconds running: $_<br>\n";
> sleep 1;
> }
>
> But, if I add a line $|++ , Apache doesn't time-out:
>
> #!/usr/bin/perl
> print "Content-Type: text/html\n\n";
> $|++;
> for (0..1000) {
> print "seconds running: $_<br>\n";
> sleep 1;
> }
>
> $| (or $OUTPUT_AUTOFLUSH in full) is a special variable in Perl. It
> makes the output of my CGI script unbuffered if its value is greater
> than 0. This second script keeps outputting to the browser (unbuffered)
> :
>
> seconds running: 0
> seconds running: 1
> seconds running: 2
> ...
> seconds running: 1000
>
> Because Apache has "something to keep outputting" all the time, it
> doesn't give a time-out here. Though in the first script, Apache waits
> until the script has ended before output. Which thus triggers the
> time-out and causes my script to end prematurely.
>
> The problem I'm facing is that I have the same issue in PHP when
> creating a large ZIP-file on-the-fly (more specifically in PhpMyAdmin's
> export interface). I searched the PHP docs for "buffer" but none of
> those functions seem to be suitable for what I want to do. Is this
> possible in PHP ?
>
> Thank you,
>
> --
> Bart

You can set the timeout value with the max_execution_time flag in using
ini_set() or in php.ini, or with set_time_limit()

The get autoflushing I'm not sure.

Read up on the output_buffering setting in php.ini as well as the
ob_implicit_flush function and setting in php.ini

This bug report http://bugs.php.net/bug.php?id=23877 may be relevant.
It implies that implicit_flush() doesn't always work as expected and
you may need to call flush() repeatedly

Tim

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация