1

I am inserting a huge data values through CSV file via HTML form.

I have used set_time_limit(0); so that script run until the whole operation is not performed.

Fatal error: Maximum execution time of 300 seconds exceeded in C:\xampp\htdocs\clytics\include\clytics.database.php on line 135

Now, I am trying to catch this fatal error.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • 1
    @JeremyMiller The answer there says to use `set_time_limit(0)`, and that's what he's done. – Barmar Jun 09 '14 at 06:35
  • actually, I want to use try, catch to handle this error. Is it possible... – Devendra Pratap Singh Jun 09 '14 at 06:36
  • You can't try-catch this error. It's not something that happens within any given block of code, it occurs outside of all that. And, good point Barmar. –  Jun 09 '14 at 06:39
  • For the try-catch consideration, see this http://stackoverflow.com/questions/6861033/how-to-catch-the-fatal-error-maximum-execution-time-of-30-seconds-exceeded-in-p –  Jun 09 '14 at 06:40
  • Use cli for this.. You can check `exec` in php for this – 웃웃웃웃웃 Jun 09 '14 at 06:43
  • Are you running this script via the command line or the PHP in Apache? Because the CLI config `php.ini` is 100% different form the Apache module config of `php.ini`. – Giacomo1968 Jun 09 '14 at 06:47

1 Answers1

2

I have used set_time_limit(0); so that script run until the whole operation is not performed.

Probably needs more memory as well. Basically your code is just a hog & you need to tame the way it is gobbling up resources.

But that is just a tangent on the overall architecture issues you might be facing.

Specific to there issue, is there something in your code that would override that value of set_time_limit(0);?

Also, ar you running this script via the command line or the PHP in Apache? Because the CLI config php.ini is 100% different form the Apache module config of php.ini.

For example, on Ubuntu the Apache PHP php.ini is here:

/etc/php5/apache2/php.ini

But the command line (CLI) php.ini is here:

/etc/php5/cli/php.ini

And if you want to brute force your script to eat up memory regardless of your config settings, you can add this to the top of your PHP file:

ini_set('MAX_EXECUTION_TIME', -1);

If one reads up more on set_time_limit this comes up:

Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.

Then reading up on max_execution_time this comes up:

This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.

But then, the magic 300 number shows up:

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

So now you know where the 300 comes from. But doing ini_set('MAX_EXECUTION_TIME', -1); should let you run the script without a timeout.

And final bit of info if none of that somehow works: Look into max_input_time:

This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins.

While max_input_time might not seem to be related, in some versions of PHP, there is a bug where max_input_time and max_execution_time are directly connected.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103