0

I have a script in php which takes data from a database and writes it in a file. The first time I ran the script I got this:

Fatal error: Maximum execution time of 240 seconds exceeded.

So I changed this time in my php.ini to 300 and ran the script again. This time, it works. However, on running the script a second time I get this error:

Fatal error: Maximum execution time of 300 seconds exceeded.

After changing the time to 300 now, it works again but only the first time. Any idea as to why I have to keep on increasing this max_execution_time?

refresh
  • 1,319
  • 2
  • 20
  • 71
  • 1
    What does the script do? Does it create more data that the script has to process on its next run? – Chris Apr 12 '16 at 08:22
  • Execution time of your script is not constant so better find average value and set little higher time than that or you can set max_execution_time to -1 so ter is not limit. – Arjun J Gowda Apr 12 '16 at 08:22
  • Is your script supposed to take so long ? Exceeded execution time is often due to a code error line an infinite loop. – FLX Apr 12 '16 at 08:27
  • The SQL query does a select * from 2 tables and put in it a file. The query returns around 71 000 lines. – refresh Apr 12 '16 at 08:35
  • You can't expect us to answer this question without telling us what the script which times out is doing in more detail. The long execution time could be legitimate or could indicate that your code is doing things suboptimally. – apokryfos Apr 12 '16 at 08:39

1 Answers1

0

At the beginning of your script you can add.

ini_set('MAX_EXECUTION_TIME', -1);

This line of code will drop the max execution time restriction of a code, allowing a php code to run forever.

DevLoots
  • 747
  • 1
  • 6
  • 21
  • 2
    While this would work, it probably just masks a deeper issue rather than solving one. – apokryfos Apr 12 '16 at 08:37
  • This line of code will drop the max execution time restriction of a code, allowing a php code to run forever. – DevLoots Apr 12 '16 at 08:43
  • 1
    I don't think this really resolves the issue. The reason is explained nicely in [this answer](http://stackoverflow.com/a/4307071/2233391) – Henders Apr 12 '16 at 09:36