I want to exit my php code after 10 seconds. Is there any possible way to do that? I have already found this code but it's not working.
set_time_limit(10); *//this line is blocked from the server*
ini_set('max_execution_time', 10);
I want to exit my php code after 10 seconds. Is there any possible way to do that? I have already found this code but it's not working.
set_time_limit(10); *//this line is blocked from the server*
ini_set('max_execution_time', 10);
Share
Improve this question
edited Jun 21, 2016 at 6:23
thor
22.6k31 gold badges105 silver badges193 bronze badges
asked Jun 21, 2016 at 6:04
SupunRSupunR
211 silver badge2 bronze badges
5
- Actually your question is pretty vague. What you actually want to do once it get exited? – Narendrasingh Sisodia Commented Jun 21, 2016 at 6:08
- Can you add more context please? Why do you want to limit the execution time? – Gordon Commented Jun 21, 2016 at 6:12
- Do you really want the script to just timeout after 10 sec? Feels like there might be a design flaw buried somewhere here. – M. Eriksson Commented Jun 21, 2016 at 6:25
- Your question is not clear, Did you just want to left your php page after every 10 seconds or you want to set max time limit for execution? – Deepak Dholiyan Commented Jun 21, 2016 at 6:33
- How you would be sure that it has been done what was intended to be done by that code? – techie_28 Commented Jun 21, 2016 at 6:47
2 Answers
Reset to default 5Did you put set_time_limit
at the begining of the script? if not - do it, because if you look at official documentation you will see next:
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 asset_time_limit(20)
is made, the script will run for a total of 45 seconds before timing out.
Also check it's return value: "Returns TRUE on success, or FALSE on failure."
PS:
"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()
, stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real."
Does it help?
All written above you can find in http://php/manual/en/function.set-time-limit.php
I think that this code may help you:
$starttime = time();
do{
//make something
}
while ((time() - $starttime)<5); //stop with 5 seconds
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399490a4626034.html
评论列表(0条)