How to solve set_time_limit not affecting PHP-CLI?
#!/usr/bin/php -q
2 second
Very hackish, but since I use cli scripts a lot, I admit shamefully to having slapped up a similar hack in the past. 2 scripts needed.
Your first cron script (the one that hangs) logs its starttime and processid in a flat file -> the function getmypid will be your friend for this. A second script run from cron every (x) minutes checks the flatfile, kills whatever has passed the alloted execution time, clears the flatfile and even logs in another file if you want.
Good luck ;)
UPDATE:
Remembered this question and came back to post this. While rummaging through Sebastian Bergmann's github account I stumbled on php-invoker. In the words of the author:
Utility class for invoking PHP callables with a timeout.
Although the current answer is very good for linux based non portable use, if cross-platform solution is needed this solution should be windows compatible, for those poor souls running on windoze. Mr Bergmann being a PHP god, I totally vouch for the quality of the script.