Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set maximum execution time in MYSQL / PHP

I have an XML document that has around 48,000 children (~50MB). I run an INSERT MYSQL query that makes new entries for each one of these children. The problem is that it takes a lot of time due to its size. After it is executed I receive this

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

How do I set the Maximum execution time to be unlimited?

Thanks

like image 207
Harris Geo Avatar asked Aug 15 '13 13:08

Harris Geo


People also ask

How do I change the maximum execution time in MySQL?

Finally, the maximum execution time can also be set for a specific SELECT statement using the MAX_EXECUTION_TIME hint directly in the query. SELECT /*+ MAX_EXECUTION_TIME(1000) */ For statements with multiple SELECT keywords, such as unions or statements with subqueries, the MAX_EXECUTION_TIME() hint.

How can I limit time in PHP?

Use PHP inbuilt function set_time_limit(seconds) where seconds is the argument passed which is the time limit in seconds. It is used, when the user changes the setting outside the php. ini file. The function is called within your own PHP code.


1 Answers

You can make it by setting set_time_limit in you php code (set to 0 for no limit)

set_time_limit(0);

Or modifying the value of max_execution_time directly in your php.ini

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 120  

Or changing it with ini_set()

ini_set('max_execution_time', 120); //120 seconds

but note that for this 3rd option :

max_execution_time

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

Source www.php.net

like image 125
Imane Fateh Avatar answered Oct 07 '22 00:10

Imane Fateh