I need to run a script into localhost (xampp) which will generate 14400 records and adds them into database, I have set the max_execution_time = 50000000000
, I dont know if I can make it unlimited by setting it to 0 or -1. But I tried this script before with this max_execution_time to 50000000000 and yet it stoped at certain point, I dont know what else could limit the execution time, I have been running this a lot of times and I am tired of waiting and failing again, what should I change before I run this script again and this time to finish the job?
Most likely you will be using loops and the set_time_limit(0) command should be at the top of the loop that causes the timeout. The parameter 0 means that no time limit will be imposed (as per the manual), therefore the script can run until completion.
Yes, it is possible to set an infinite execution time for the PHP Script. We can do it by adding the set_time_limit() function at the beginning of the PHP script. The set_time_limit() function takes only one parameter that is int value which is in seconds and it returns a boolean value.
To increase the script execution time, you can use the following snippet at the top of your script. ini_set ( 'max_execution_time' , '300' ); In the above example, it would set the max_execution_time directive to 300 seconds.
It is used when you need to override the configuration value at run-time. This function is called from your own PHP code and will only affect the script which calls this function. Use init_set('max_execution_time'0) when you want to set unlimited execution time for the script.
Add the following code to set unlimited execution time for a PHP script: You can also update max_execution_time in php.ini If the value is 0, it is actually unlimited. Otherwise it is that number of seconds.
To increase the script execution time, you can use the following snippet at the top of your script. 1 ini_set('max_execution_time', '300'); In the above example, it would set the max_execution_time directive to 300 seconds.
Let’s assume that a script is executed for 10 seconds, and then the set_time_limit function is called to set the script execution time to 30 seconds. In that case, a script would run for a total of 40 seconds before it’s terminated.
The max_execution_time directive defines the maximum execution time for your PHP scripts and applications. If not configured, the default maximum execution time for a PHP script is 30 seconds. PHP will timeout and exit with a fatal error once it reaches the time limit.
You'll have to set it to zero. Zero means the script can run forever. Add the following at the start of your script:
ini_set('max_execution_time', 0);
Refer to the PHP documentation of max_execution_time
Note that:
set_time_limit(0);
will have the same effect.
Your script could be stopping, not because of the PHP timeout but because of the timeout in the browser you're using to access the script (ie. Firefox, Chrome, etc). Unfortunately there's seldom an easy way to extend this timeout, and in most browsers you simply can't. An option you have here is to access the script over a terminal. For example, on Windows you would make sure the PHP executable is in your path variable and then I think you execute:
C:\path\to\script> php script.php
Or, if you're using the PHP CGI, I think it's:
C:\path\to\script> php-cgi script.php
Plus, you would also set ini_set('max_execution_time', 0);
in your script as others have mentioned. When running a PHP script this way, I'm pretty sure you can use buffer flushing to echo out the script's progress to the terminal periodically if you wish. The biggest issue I think with this method is there's really no way of stopping the script once it's started, other than stopping the entire PHP process or service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With