472,958 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Long sleep() and time-out's

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.
Jun 14 '06 #1
22 5785
Rik
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
Jun 14 '06 #2
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)
Jun 14 '06 #3
Rik
> 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
Jun 14 '06 #4
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?
Jun 14 '06 #5
Rik
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
Jun 14 '06 #6
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).
Jun 14 '06 #7
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
==================
Jun 15 '06 #8
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.
Jun 15 '06 #9
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
==================
Jun 16 '06 #10
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.
Jun 16 '06 #11
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

Jun 16 '06 #12
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-

Jun 16 '06 #13
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.
Jun 16 '06 #14
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 :-)
Jun 16 '06 #15
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/

Jun 18 '06 #16
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.
Jun 18 '06 #17
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

Jun 18 '06 #18
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.
Jun 19 '06 #19
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/

Jun 19 '06 #20
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

Jun 19 '06 #21
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.
Jun 19 '06 #22
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

Jun 20 '06 #23

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

Similar topics

5
by: Anks | last post by:
hi I am displaying a digital clock in an applet.I am using Thread.sleep (1000) for counting every second.This works fine some times but some times my clock just slows down or give an...
7
by: Colin Brown | last post by:
Python 2.3.3 Under Windows NT: Negative Int or Real -> sleeps for a long time Under Linux: Returns IOError: Invalid argument I consider both of these unfriendly results and expected the...
9
by: Brian Roberts | last post by:
I have a command line Python program that sometimes takes a bit (several minutes) to run. I want to provide an optional method for an impatient user (me!) to check the status of the program. The...
5
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
0
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
6
by: seb | last post by:
Hi, I am using pygtk for the first times. I am wondering what would be the best "pattern" to interface pygtk with a thread. The thread is collecting informations (over the network for...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.