Reputation: 533
Is there any problem if i use <?php sleep(60); ?>
in my script for 30 times, so that the script will load and finish its works in 30 minutes, is there chance of any problem?
Note: if it fails , is there any way to do like this?
Upvotes: 1
Views: 583
Reputation: 18250
There are several problems with this idea.
n
seconds. This will be on top of your scripts "natural" run-time, so the total execution time will be ( sleep(s) * times called ) + execution_time
when executing the script in a cgi environment or in the php apache module, by default you have a max_execution_time
of 30s after which your script will stop execution. On CLI the default is 0 =~ unlimited.
http://php.net/manual/en/info.configuration.php#ini.max-execution-time
Finally, as stated in the comments, if your script is called from a browser, the webserver will run into a timeout much earlier.
Upvotes: 0
Reputation:
The client is likely to stop listening for a response, but it is still possible for the script to complete execution. You would have to configure your PHP installation for long execution times though.
If you are using a browser and AJAX requesting data that will be returned after 30 minutes, it is better to poll a static resource.
When you want to start the script, send an AJAX request to it. This request will eventually time out. Set up your script so that it saves its output to a static resource when it is done (text file / image / etc; depends on what your script is supposed to return). Poll this resource every five minutes using AJAX, and you will get the response from the server when it is ready.
Upvotes: 2
Reputation: 5351
It makes no difference if you call sleep(60)
for 30 times or sleep(60 * 30)
once.
Take a look at the php function set_time_limit, because the standard is 30 seconds or so. After that, your script will be terminated.
However, I don't know if there is a browser willing to wait so long for your request. What are you trying to achieve?
Upvotes: 0