Is there a way to timeout a function? I have 10 minutes to perform a job. The job includes a for loop, here is an example:
What you want is to use the pcntl_alarm function, which will trigger a SIGALRM signal on timeout.
For example:
// 10 minutes
pcntl_alarm( 600 );
pcntl_signal(SIGALRM, function() { print( "Timed-out!\n" ); exit( 0 ); });
Please see here the PHP manual for more on this: http://php.net/manual/en/function.pcntl-alarm.php