473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Unbuffer output in PHP

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

May 20 '06 #1
2 2072
tim

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

May 20 '06 #2
tim wrote:
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


The max_execution_time flag does precisely what I was looking for.
Thanks for your help.

--
Bart

May 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
0
by: Krutibas Biswal | last post by:
Hi, I am using a script 'unbuffer' for unbuffering my outputs when using pipes. This script is based on expect and looks like this : ----------------------------------------------...
3
by: edgekaos | last post by:
Is method 2 valid? Method 1: wstring input = L"STRING"; wstring output = input; transform(output.begin(), output.end(), output.begin(), towupper); Method 2: wstring input = L"STRING";...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
24
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
0
by: newbie | last post by:
i'm a newbie of c language. can anyone help me to implement the code so that I can get the ciphertext from the output. thanks. #ifndef _3DES_H #define _3DES_H #ifndef uint8 #define uint8 ...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
3
by: MatsL | last post by:
Hi, This is seriously driving me crazy, could anyone explain to me why neither of these doesn't produce XHTML compliant output (it is being called in Render() btw): output.WriteLine("<img...
2
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.