1

I have a PHP script running a loop which could go on for hours on end. However after about 50 minutes I get the following error although the script is far beyond 60 seconds:

Fatal error: Maximum execution time of 60 seconds exceeded in /path/script.php on line 275

The memory usage by the time the script fails is 11359848 Bytes - 10.8336 MB. Any ideas what sort of thing could actually be causing the script to trip out like this?

3
  • what's in script.php. I mean r u doing dataaccess in script.php Commented Jul 3, 2012 at 18:22
  • Are you running this script from the command line or via a webserver and remote web browser? Commented Jul 3, 2012 at 18:30
  • CURL requests and MySQL input. Currently web browser, will be crontab eventually. Commented Jul 4, 2012 at 0:14

1 Answer 1

6

The maximum execution time is not real time but CPU time.

So if send e.g. a HTTP request that takes 10 hours to finish (i.e. you wait for I/O) you can easily stay within the 60-second limit. But if try breaking a hash using brute force (i.e. something where the script is actually doing something) you'll hit the time limit after pretty much 60s of real time.

The solution for your problem is pretty simple: set_time_limit(0); disables the time limit unless PHP is running in safe_mode, but if that's the case it's time to chance the hosting company.

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

5 Comments

I'm pretty sure there is more to it than that, at least if the script is accessed through a webserver and browser. If I recall, there are other things like TCP disconnects which will stop scripts.
Yes, but these do not cause the error the OP got. Besides that, if he has a script running that long I really hope he's not running it through a webserver.
Agreed on both counts. If you could, add that this function has no effect in safe mode and maybe point out the php.ini option. Anyway, +1
Luckily that horrible misfeature is deprecated and will eventually be removed from PHP - that's why I didn't mention it.
Seems to have done the trick. Would this kind of script have a massive impact on a web server then? Currently I'm running it on my Mac and it doesn't seem to have much impact on the processor and in total and the highest memory usage at any point throughout the script is 14 MB at the end which I am working on reducing. And yes it is accessing a MySQL database and making CURL requests. Thanks

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.