make script execution to unlimited

PhpXampp

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

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.

Solution 3 - Php

As @Peter Cullen answer mention, your script will meet browser timeout first. So its good idea to provide some log output, then flush(), but connection have buffer and you'll not see anything unless much output provided. Here are code snippet what helps provide reliable log:

set_time_limit(0);
...
print "log message";
print "<!--"; print str_repeat (' ', 4000); print "-->"; flush();
print "log message";
print "<!--"; print str_repeat (' ', 4000); print "-->"; flush();

Solution 4 - Php

The following code in the .htaccess file worked for me:

php_value max_execution_time 0
RewriteEngine On
RewriteRule .* - [E=noconntimeout:1]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_php5.c>
#Session timeout
php_value session.cookie_lifetime 10
php_value session.gc_maxlifetime 10
</IfModule>

Solution 5 - Php

"hek2mgl" answer above didn't work for me, so I used -1 i.e.,

ini_set('max_execution_time', -1);

Hope it helps someone.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTooCooLView Question on Stackoverflow
Solution 1 - Phphek2mglView Answer on Stackoverflow
Solution 2 - PhpPeter CullenView Answer on Stackoverflow
Solution 3 - PhpLeonidMewView Answer on Stackoverflow
Solution 4 - PhpYahya BView Answer on Stackoverflow
Solution 5 - PhpNobodyView Answer on Stackoverflow