Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Refresh Page

Tags:

php

Currently I have a problem with GoDaddy and its hosting. The maximum amount of time allowed for a PHP script to run is set to 120 seconds = 2 mins.

Sometimes when I run my script, it takes more than 120 seconds and sometimes it takes 30 seconds.

When it takes over 120 seconds, I get a Internal Server Error (500).

The question I have is, is it possible to figure out if a script run time is at 110 seconds and then refresh the page so that the Internal Server Error does not occur.

like image 915
Sohel Mansuri Avatar asked Nov 03 '22 01:11

Sohel Mansuri


1 Answers

If what ever is causing your script to run long is some sort of self contained blocking function (like a database query), then you are kind of screwed.

If not, say you are in a very large loop, then just do the math your self.

At the very start of your script, save the current time: $t_start = time();

Then at the top of your loop, do a $runtime = time() - $t_start; then you have how long you have been running, and can use that to break your loop gracefully if nearing your 120 limit.

like image 171
Uberfuzzy Avatar answered Nov 09 '22 13:11

Uberfuzzy