473,836 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,30 0));
}

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 5913
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,30 0));
}

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<=ra nd(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,30 0));
}

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_t ime 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******@NOSPAM betadome.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<=r and(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<=ra nd(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*******@attgl obal.net
=============== ===
Jun 15 '06 #8
On Thu, 15 Jun 2006 00:01:42 -0400, Jerry Stuckle
<js*******@attg lobal.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*******@attg lobal.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*******@attgl obal.net
=============== ===
Jun 16 '06 #10

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

Similar topics

5
13982
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 interrupted exception .I am not calling Thread.interrupt anywhere in my program. why is it happening? how to fix the problem? Anks
7
10325
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 preferable silent time.sleep(0) in much the same way that slicing a string beyond the ends returns an empty string. Colin Brown PyNZ
9
2165
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 type and amount of status information doesn't fit nicely into a --verbose or logger -- either too little or too much information at different points. I think an optional web page would be convenient interface. The Python program would listen...
5
9110
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 terminate the sleep() following execution > of that signal's catching routine. Also, the suspension time may > be longer than requested by an arbitrary amount because of the > scheduling of other activity in the system. I don't understand the...
9
7137
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 when I tried the program on the Win98 system it will be running on, I get the following error: Cast from string "2076719" to type 'Long' is not valid I am not sure why I only get this error on the Win98 system or how to go about correcting...
0
374
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 function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems...
5
3115
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 i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
17
6442
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. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
9
3276
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 problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
6
2874
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 example) or is doing some long calculations.
0
9816
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10840
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.