A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearDoes sleep time count for execution time limit? - page 1
User InfoPosts
Does sleep time count for execution time limit?#1
I have two questions concerning the sleep() function in PHP:

Does the sleep time affect the maximum execution time limit of my PHP scripts? Sometimes, PHP shows the message "maximum execution time of 30 seconds exceeded". Will this message appear if I use sleep(31)?
Are there any risks when using the sleep()function? Does it cost a lot of CPU performance?

posted date: 2009-04-11 15:06:00

Re: Does sleep time count for execution time limit?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-11 15:06:01

Re: Does sleep time count for execution time limit?#3
You should try it, just have a script that sleeps for more than your maximum execution time.<?php sleep(ini_get((max_execution_time() + 10);?>Spoiler: Under Linux, sleeping time is ignored, but under Windows, it counts as execution time.

posted date: 2009-04-11 15:09:00

Re: Does sleep time count for execution time limit?#4
a) Yes, it counts toward the time limit (so sleep(31) will trigger an error)b) It does the opposite of costing CPU performance - it lets other applications use the CPU (when an application sleeps, the CPU usage of that application will be near 0%). Aside from taking time away from the user, I can(t really think of any risks of using this.

posted date: 2009-04-11 15:10:00

Re: Does sleep time count for execution time limit?#5
It only affects script time not system calls like sleep(). There is apparently a bug where on Windows sleep() is included. Max execution time is about real-time, not CPU time or anything like that. You can change it however:max_execution_time directive in your php.ini. This is a global setting;Using ini_set() with the above directive. This will change it only for the currently executing script only for that execution;set_time_limit(): also a local change.As for the difference between the last two, I believe max_execution_time is a fixed quantity. Running:ini_set((max_execution_time(, 60);will limit to the script to 60 seconds. If after 20 seconds you call:set_time_limit(60);the script will now be limited to 20 + 60 = 80 seconds.

posted date: 2009-04-11 15:13:00

Re: Does sleep time count for execution time limit?#6
From the PHP sleep() page, there(s this user-contributed note:Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, etc. is not included when determining the maximum time that the script has been running.

posted date: 2009-04-11 15:15:00

Re: Does sleep time count for execution time limit?#7
Just to add, this behavior is exhibited on *nix only. On windows set_time_limit() wins every time.

posted date: 2009-04-11 15:20:00

Re: Does sleep time count for execution time limit?#8
Probably because you changed your answer to be correct after the downvote.

posted date: 2009-04-11 15:21:00

Re: Does sleep time count for execution time limit?#9
The cause: I can only run cronjobs every 5 minutes. So I thought I could use ... $waittime = mt_rand(0, 290); sleep($waittime); ... and execute the code 4 times simultaneously. So I should have a cron at 4 different points in time.

posted date: 2009-04-11 15:25:00

Re: Does sleep time count for execution time limit?#10
I startet some scripts with sleep times of more than 100 seconds. Now my website doesn't load any more. Probably the server can only run x scripts simultaneously and there are x scripts sleeping. Could that be true?

posted date: 2009-04-11 15:28:00

Re: Does sleep time count for execution time limit?#11
There's no edited time at the bottom, how could he have changed it?

posted date: 2009-04-11 15:30:00

Re: Does sleep time count for execution time limit?#12
I don't know why it was downvoted. I am the questioner and you answered my question well. Thanks!

posted date: 2009-04-11 15:33:00

select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.