It's 10 seconds on my server, and that's not enough for what I'm trying to do. It's been disabled by the webhost too.
If, after a certain amount of time of executing, I execute a separate PHP page, does that count towards the same time or does it start over on that page?
Is there 开发者_开发问答another way around it?
Easy way around max execution time is to set time limit like so:
set_time_limit(0);
A possible workaround might involve setting cron jobs to do your task in smaller parts. I appreciate this is probably quite undesirable.
You can get around it using Javascript; have your page finish its own execution before the timeout expires, save its state, and return Javascript to the user which causes the client to request a new page that continues processing with a fresh time limit.
I don't recommend this.
Try set_time_limit()
However
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini
When you include more and more files, it does not reset counter
There is no way around it - given that your webhost configured its server properly.
The amount of time refers to all scripts, not separately.
If, after a certain amount of time of executing, I execute a separate PHP page, does that count towards the same time or does it start over on that page?
If you call the separate PHP page using a HTTP request (not an include), with file_get_contents('http://example.com/mypage.php');
for example, it does not count towards the same time. It starts over again on that page.
I have used this trick myself several years ago...
Other than that, try set_time_limit
and consider scheduling an "every minute" cronjob to perform the task.
As @Borealid said you could use javascript and ajax requests to continue executing your script using previously saved state. For that you can use serialize() to save in session what variables you or object you might have, and using a counter or any other tool you find useful, to keep track of progress. I used a similar technique several years ago, actually refreshing the page after every step that was done, all in order to see any outputfrom it, as if I would have let it finish, I might have taken several days until any output. You could try that also. the maximum execution time is applied on each request.
精彩评论