By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

How to handle lengthy operations?

P: n/a
Hi

I have a piece of code that can take a couple of minutes to run,
causing the browser to time out.

Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?

Thanks.
May 9 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
At Thu, 10 May 2007 00:43:26 +0200, Gilles Ganault let his monkeys type:
Hi

I have a piece of code that can take a couple of minutes to run,
causing the browser to time out.

Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?

Thanks.
Are you sure it's not the server timing out? max_execution_time is a
setting in php.ini, defaults to 30 secs I believe.

You could, during processing, use ob_start() and ob_flush() to send some
stuff to the browser repeatedly.

Sh.
May 9 '07 #2

P: n/a
Gilles Ganault wrote:
Hi

I have a piece of code that can take a couple of minutes to run,
causing the browser to time out.

Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?

Thanks.
Hi Gilles,

here are two littels hints:

http://de2.php.net/ignore_user_abort
http://de3.php.net/set_time_limit
hth,
Roy
May 10 '07 #3

P: n/a
On 10 ΝΑΚ, 02:43, Gilles Ganault <nos...@nospam.comwrote:
Hi

I have a piece of code that can take a couple of minutes to run,
causing the browser to time out.

Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?

Thanks.
Try to use AJAX. Redirect user to "Please wait..." page which one will
check if operations are completed and make automatic redirect.

May 10 '07 #4

P: n/a
On May 9, 3:43 pm, Gilles Ganault <nos...@nospam.comwrote:
Hi

I have a piece of code that can take a couple of minutes to run,
causing the browser to time out.

Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?

Thanks.

What browser are you using and what is the code trying to do?

May 10 '07 #5

P: n/a
Gilles Ganault wrote:
Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?
Schraalhans Keukenmeester's point is an important one: the browser is not
the only thing with a timeout -- mod_php has its own timeout too.

Increase the max execution time as he said. To solve browser timeout
issues, slowly feed it some dummy data. Assuming that your script is
outputting HTML or XML, you could include something like this inside one
of your loops:

echo "<!-- x -->\n";

This assumes of course that you don't need to output any HTTP headers as
part of this long-running code, as body output obviously prevents the
header() function from working.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 10 '07 #6

P: n/a
C.
On 10 May, 20:46, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
Gilles Ganault wrote:
Is there a way to send empty, fake data to keep the browser happy
while the code is running on the server?

Schraalhans Keukenmeester's point is an important one: the browser is not
the only thing with a timeout -- mod_php has its own timeout too.
A better solution might be to run asynchronously in a seperate program
group (running something in the background of a webserver process is
not a good idea). It's quite easy on Linux/Unix:

$cmd='/path/to/php/script';

`at now php $cmd`;

I've heard that `start php $cmd` will give similar results on MS
platforms but you'd need to investigate further.

C.

May 11 '07 #7

P: n/a
On Thu, 10 May 2007 20:46:40 +0100, Toby A Inkster
<us**********@tobyinkster.co.ukwrote:
>This assumes of course that you don't need to output any HTTP headers as
part of this long-running code, as body output obviously prevents the
header() function from working.
Thank everyone for the tips!
May 12 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.