Hi
The script I'm writing needs to wait a random amount of time (1-300s)
between each iteration of a loop, eg.
while(condition) {
do something
//wait between 1s and 5 minutes
sleep(rand(1,300));
}
Problem is, a browser times out if it doesn't get an answer within
about 30 seconds. Is the idea of having a PHP script sleep for a
longer amount of time incompatible with web applications? Any
work-around?
Thank you. 22 5682
Vincent Delporte wrote: Hi
The script I'm writing needs to wait a random amount of time (1-300s) between each iteration of a loop, eg.
while(condition) { do something //wait between 1s and 5 minutes sleep(rand(1,300)); }
Problem is, a browser times out if it doesn't get an answer within about 30 seconds. Is the idea of having a PHP script sleep for a longer amount of time incompatible with web applications? Any work-around?
Feed some bogus information?
for($i=0;$i<=rand(1,60);$i++){
echo ' ';
sleep(5);
}
Not very elegant, but gets the job done I think.
Grtz,
--
Rik Wasmus
Vincent Delporte wrote: Hi
The script I'm writing needs to wait a random amount of time (1-300s) between each iteration of a loop, eg.
while(condition) { do something //wait between 1s and 5 minutes sleep(rand(1,300)); }
Problem is, a browser times out if it doesn't get an answer within about 30 seconds. Is the idea of having a PHP script sleep for a longer amount of time incompatible with web applications? Any work-around?
Use set_time_limit: http://php.net/set_time_limit
From the manual: Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
Especially that last part should be useful to you.
--
Kim André Akerø
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
> Vincent Delporte wrote: Problem is, a browser times out if it doesn't get an answer within
-----------------^^^^^^
Kim André Akerø wrote: Use set_time_limit: http://php.net/set_time_limit
Nope, except if the OP has got his question wrong.
Browser time-outs are beyond settings you can control, you can only
urge/fool them.
Grtz
--
Rik Wasmus
On Wed, 14 Jun 2006 18:19:45 +0200, "Rik" <lu************@hotmail.com>
wrote: for($i=0;$i<=rand(1,60);$i++){ echo ' '; sleep(5); }
Not very elegant, but gets the job done I think.
Thx but it doesn't work: I don't see how I can have the script pause
for 1-300 seconds, while still send some empty string to the browser
every 5 seconds just to avoid a time-out error. Did I get this wrong?
Vincent Delporte wrote: On Wed, 14 Jun 2006 18:19:45 +0200, "Rik" <lu************@hotmail.com> wrote: for($i=0;$i<=rand(1,60);$i++){ echo ' '; sleep(5); }
Not very elegant, but gets the job done I think.
Thx but it doesn't work: I don't see how I can have the script pause for 1-300 seconds, while still send some empty string to the browser every 5 seconds just to avoid a time-out error. Did I get this wrong?
It depends.
What is the exact reason of your pause?
Grtz,
--
Rik Wasmus
On Wed, 14 Jun 2006 21:40:08 +0200, "Rik" <lu************@hotmail.com>
wrote: What is the exact reason of your pause?
I have a main loop that fetches information from another site, but to
simulate fake users, I need these fetching to occur at random
intervals, between 1 and 300s. The problem is that after any sleep >
30 seconds, the browser reports a 504 (time-out).
Vincent Delporte wrote: On Wed, 14 Jun 2006 21:40:08 +0200, "Rik" <lu************@hotmail.com> wrote:
What is the exact reason of your pause?
I have a main loop that fetches information from another site, but to simulate fake users, I need these fetching to occur at random intervals, between 1 and 300s. The problem is that after any sleep > 30 seconds, the browser reports a 504 (time-out).
A 504 sounds like the browser timing out (although I guess it could be PHP).
As has been indicated before, you can change the PHP timeout value, but there's
nothing you can do about the browser.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
On Thu, 15 Jun 2006 00:01:42 -0400, Jerry Stuckle
<js*******@attglobal.net> wrote: As has been indicated before, you can change the PHP timeout value, but there's nothing you can do about the browser.
OK, so it's hopeless. It's a shared PHP server to which I don't have
access, so no fiddling with PHP.INI. I'll rewrite this in Delphi
instead.
Thanks everyone.
Vincent Delporte wrote: On Thu, 15 Jun 2006 00:01:42 -0400, Jerry Stuckle <js*******@attglobal.net> wrote:
As has been indicated before, you can change the PHP timeout value, but there's nothing you can do about the browser.
OK, so it's hopeless. It's a shared PHP server to which I don't have access, so no fiddling with PHP.INI. I'll rewrite this in Delphi instead.
Thanks everyone.
If it's a timeout problem in the browser it doesn't matter what language you
use. The problem isn't in anything you can control.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
On Thu, 15 Jun 2006 23:51:18 -0400, Jerry Stuckle
<js*******@attglobal.net> wrote: If it's a timeout problem in the browser it doesn't matter what language you use. The problem isn't in anything you can control.
I meant that I would rewrite the algo in Delphi instead of a PHP
script. That will solve the sleep(rand()) issue. Thanks.
On Fri, 16 Jun 2006 07:08:31 +0200, Vincent Delporte wrote: If it's a timeout problem in the browser it doesn't matter what language you use. The problem isn't in anything you can control.
I meant that I would rewrite the algo in Delphi instead of a PHP script. That will solve the sleep(rand()) issue. Thanks.
Unless I'm missing something Jerry's answer still stands. If you write a
server-side CGI exe using Delphi, the browser will still timeout while
waiting for your random wait.
If you are planning on running the Delphi utility through some other
method (at, scheduled jobs, etc) then you could do the same thing with PHP
(using set_time_limit()) and it would work equally fine.
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer http://www.gphpedit.org | PHP editor for Gnome 2 http://www.andyjeffries.co.uk | Personal site and photos
Andy Jeffries wrote: On Fri, 16 Jun 2006 07:08:31 +0200, Vincent Delporte wrote: If it's a timeout problem in the browser it doesn't matter what language you use. The problem isn't in anything you can control. I meant that I would rewrite the algo in Delphi instead of a PHP script. That will solve the sleep(rand()) issue. Thanks.
Unless I'm missing something Jerry's answer still stands. If you write a server-side CGI exe using Delphi, the browser will still timeout while waiting for your random wait.
If you are planning on running the Delphi utility through some other method (at, scheduled jobs, etc) then you could do the same thing with PHP (using set_time_limit()) and it would work equally fine.
Cheers,
Andy
You could always respond to the browser before you go into the sleep
loop and redirect it to a 'waiting...' page with a meta-refresh on it.
The waiting page can check whether the fetch from the remote is complete
and either a) display a new page with the details or b) call itself and
loop again.
Maybe a c) if we have looped too many times to say 'the data isn't coming'.
-david-
On Fri, 16 Jun 2006 20:13:37 GMT, Andy Jeffries
<ne**@andyjeffries.co.uk> wrote: Unless I'm missing something Jerry's answer still stands. If you write a server-side CGI exe using Delphi, the browser will still timeout while waiting for your random wait.
No, I meant rewriting this as a Delphi client app instead of a PHP
script. Too bad that the whole thing breaks because I didn't think
about the sleep() thing. No biggie though. Thanks everyone for your
help.
On Fri, 16 Jun 2006 16:20:42 -0400, David Haynes
<da***********@sympatico.ca> wrote: You could always respond to the browser before you go into the sleep loop and redirect it to a 'waiting...' page with a meta-refresh on it. The waiting page can check whether the fetch from the remote is complete and either a) display a new page with the details or b) call itself and loop again.
Maybe a c) if we have looped too many times to say 'the data isn't coming'.
Thanks a bunch for the idea, but it's just too complicated. I'll be
done in Delphi this week-end :-)
Vincent Delporte wrote: Hi
The script I'm writing needs to wait a random amount of time (1-300s) between each iteration of a loop, eg.
while(condition) { do something //wait between 1s and 5 minutes sleep(rand(1,300)); }
<snip>
Not sure, if you're looking for
<http://in2.php.net/ignore_user_abort> and
<http://in2.php.net/features.connection-handling>
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
On 18 Jun 2006 03:58:18 -0700, "R. Rajesh Jeba Anbiah"
<ng**********@rediffmail.com> wrote: Not sure, if you're looking for <http://in2.php.net/ignore_user_abort> and <http://in2.php.net/features.connection-handling>
Thanks, but it seems like the shared server I use ignores those
settings.
On Fri, 16 Jun 2006 23:07:45 +0200, Vincent Delporte wrote: Unless I'm missing something Jerry's answer still stands. If you write a server-side CGI exe using Delphi, the browser will still timeout while waiting for your random wait.
No, I meant rewriting this as a Delphi client app instead of a PHP script. Too bad that the whole thing breaks because I didn't think about the sleep() thing. No biggie though. Thanks everyone for your help.
You could have done it as a PHP script and just run it on your local
machine (as you were doing with Delphi) using the PHP binary that is
installed with newer versions of PHP.
I know how you feel though (exactly, I used to be a Delphi programmer) but
it really will do you great bounds to resist the temptation to go back to
the old familiar when learning a new language.
It's hard, I'm as guilty as anyone else, but it really does you good.
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer http://www.gphpedit.org | PHP editor for Gnome 2 http://www.andyjeffries.co.uk | Personal site and photos
On Sun, 18 Jun 2006 21:31:51 GMT, Andy Jeffries
<ne**@andyjeffries.co.uk> wrote: You could have done it as a PHP script and just run it on your local machine (as you were doing with Delphi) using the PHP binary that is installed with newer versions of PHP.
Mmm... Maybe I'll do that, although i'd rather run it from the coloc
server. Either way, it's good training with regexes :-)
Thx.
Vincent Delporte wrote: On 18 Jun 2006 03:58:18 -0700, "R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote: Not sure, if you're looking for <http://in2.php.net/ignore_user_abort> and <http://in2.php.net/features.connection-handling>
Thanks, but it seems like the shared server I use ignores those settings.
I would suggest you to check the links.
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
On Mon, 19 Jun 2006 03:00:29 +0200, Vincent Delporte wrote: You could have done it as a PHP script and just run it on your local machine (as you were doing with Delphi) using the PHP binary that is installed with newer versions of PHP.
Mmm... Maybe I'll do that, although i'd rather run it from the coloc server. Either way, it's good training with regexes :-)
Sorry, I obviously haven't been very clear... My point was if you write it
in Delphi as a CGI-EXE handler and connect to it with a browser, then
you'll get the timeouts in exactly the same way (as it's the browser
timing out). If you run the Delphi EXE locally (or on the server using
CRON/AT/scheduling) then you can do exactly the same thing with PHP using
the command line binary for PHP and achieve perfect results.
My point is, redoing it in Delphi gives you nothing (except a Windows
interface if you want that).
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer http://www.gphpedit.org | PHP editor for Gnome 2 http://www.andyjeffries.co.uk | Personal site and photos
On Mon, 19 Jun 2006 07:30:47 GMT, Andy Jeffries
<ne**@andyjeffries.co.uk> wrote: My point is, redoing it in Delphi gives you nothing (except a Windows interface if you want that).
I know, but since I was only getting started, it's no big deal. I'll
just keep in mind that PHP and long sleep()'s aren't a good idea.
Cheers.
On Mon, 19 Jun 2006 21:51:15 +0200, Joe DiMaggio wrote: My point is, redoing it in Delphi gives you nothing (except a Windows interface if you want that).
I know, but since I was only getting started, it's no big deal. I'll just keep in mind that PHP and long sleep()'s aren't a good idea.
*when used in a browser-server context*
Using a PHP CLI binary, it's fine.
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer http://www.gphpedit.org | PHP editor for Gnome 2 http://www.andyjeffries.co.uk | Personal site and photos This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by Anks |
last post: by
|
7 posts
views
Thread by Colin Brown |
last post: by
|
9 posts
views
Thread by Brian Roberts |
last post: by
|
5 posts
views
Thread by Erich Schreiber |
last post: by
|
9 posts
views
Thread by rsine |
last post: by
|
reply
views
Thread by Max |
last post: by
|
5 posts
views
Thread by Sinan Nalkaya |
last post: by
|
17 posts
views
Thread by OlafMeding |
last post: by
|
9 posts
views
Thread by esakal |
last post: by
|
6 posts
views
Thread by seb |
last post: by
| | | | | | | | | | |