Where can I host a long running php script?

Highschooled

Power Member
Joined
Jul 31, 2011
Messages
517
Reaction score
454
My official hosting is hostwinds, but I have a php script I'm running that goes through lists for me, pretty simple stuff but the script will take hours (huge list) and hostwinds is set to timeout scripts after 5 minutes and send a 500 internal error message.

"This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'."

Where can I host this php script so that it can run for as long as it needs to?
 
Chunk up your processes. Instead of running one process on the entire list use cronjobs to launch your PHP script every X amount of minutes and have your script only process a small portion of the list. Like this you can run through your entire list over the course of a day without exceeding the 5 minute timeout.
 
Almost all hosts have the timeout set at 10 minutes. PHP default timeout may be set to 30 seconds, which can be bypassed by using set_time_limit, which will then give us the maximum possible time for execution, say 5 in your case.

The only possible way to make a way through this is to split the whole work into chunks. If it processes a file, set a cron that runs every minute and process a part of the array. Likewise, with designing a better workflow, you can get the stuff done without hitting the time limit.

Pretty sure that you can optimize the code. I will take a look if you want.

Cheers!
 
You have some options.
1. Set set_time_limit to 0 from php.ini
2. Run your script as a cron job from terminal. When you run from terminal, there's no timeout.
3. Break your script and go for some data in each run. This can be done simply by making a database table for your data, setting all jobs to not processed at first, and setting them processed once you process each one. Then just call select * from jobs where processed = 0.
 
Get a VPS instead of shared hosting.
 
The best solution would be a VPS, you can customise PHP settings as you wish. Also VPS are cheap
 
Back
Top