I have a PHP script that has a runtime of 34 seconds. But it dies after 30 seconds. I guess my webhost a time limit of 30 seconds.
I am thinking of splitting the script into two parts say PHP-1 and PHP-2.
Can I call PHP-2 from PHP-1 and kill PHP-1?
Both scripts have to run in sequence, so calling both of them using cron is not possible. [ My host provides cron with interval 5 mins and does not allow to change the start time]
-Will this circumvent the time limit set by host?
You should use the set_time_limit() function, it helps in most cases.
Alternatively, on Linux/Unix, you can try running the script as a background process. PHP CLI can be used for this purpose, the scripts running via CLI have no time limit. You can use exec/system or similar PHP functions to fireup the PHP CLI and have it run a PHP script in background, returning control to the script immediately. In most cases, a PHP script running via CLI behaves just like it would do in CGI environment except for few environment related differences, such as no time limit.
Here is one way to do it:
More details at: Running a Background Process in PHP