5

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.

9
  • 1
    Can't you use set_time_limit()? Commented Apr 2, 2013 at 0:34
  • You might be able to do something with microtime(); but as for the refreshing I dont have any idea. Commented Apr 2, 2013 at 0:36
  • @kingkero, that would just set the time limit. I need to know if the time limit is reached and if it is, I need to refresh the page. Commented Apr 2, 2013 at 0:36
  • stackoverflow.com/questions/6486364/… Commented Apr 2, 2013 at 0:37
  • 1
    no you can't periodically check in on your script like setInterval with javascript. PHP is a single-threaded. Commented Apr 2, 2013 at 0:53

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.