1

Is there any way we can perform an action if the php script execution time exceeds a certain time?

I could see there is set_time_limit function which throws a fatal error after a certain time. But I am not able to catch this fatal error and perform an action in this case.

Thanks in advance

Kiran
  • 896
  • 1
  • 6
  • 25

1 Answers1

6

Could be wrong but I thnk the suggested dupe would end the script, while it sounds like you want to continue the script but end that loop part of it after x seconds.

If so before you start your loop set the time -

$starttime = time();

then within your loop add an -

$now = time()-$starttime;
if ($now > 30) {             //assuming you're looking at 30 seconds
break;
}

then end your loop. After 30 seconds the loop will stop and the script will progress.

NickW
  • 141
  • 1
  • 6