Set maximum execution time in PHP - php

I tried to increase the max execution time in my php.ini file. It doesn't work, however. Considering the fact that I' ve got a large file (containing 300 pages) I have to download using PHPEXCEL, I did the following in my php. ini file:
max_execution_time = 999999999
max_input_time = 9999999
max_input_nesting_level = 64
memory_limit = 128M
Is there anyone who knows what to do in this situation?

You can use 0 :
max_execution_time = 0
That will disabled the limitation. Don't forget to restart apache after.
You can also user the PHP version :
<?php set_time_limit(0); ?>

If you don't want a limit, then you can use this:
set_time_limit(0);
But only if safe_mode is off, otherwise you can use ini_set:
ini_set('max_execution_time', 300); // 300 Seconds
Thanks.

On some of my php scripts that take long time to run I always use the following code at the top:
set_time_limit(0);
ignore_user_abort(1);
Explanation:
set_time_limit(0);
We're telling php the script can run for unlimited time.
ignore_user_abort(1);
We're telling php to continue running the script even if the user disconnects.
i.e.: closing the browser or disconnect from a SSH session.

Related

Maximum execution time of 300 sec exceeded

Why php always give me that error ? I changed php.ini values to :
max_execution_time = 99999 ;
max_input_time = 99999;
max_input_nesting_level = 64;
memory_limit = 256M;
max_input_vars = 10000;
i have created .htaccess file where i put :
php_value max_execution_time 9999
i have located php.ini 50 times to be sure i am at right location.
I have set :
set_time_limit(9999);
at the begining of my php script.
I have restarted MAMP 50 times, even laptop.
If i use phpinfo(); at the begining of my php script i can see both values (local and master) are set to 99999
I changed phpmyadmin conf located in MAMP\bin\phpMyAdmin\libraries\config.default.php to :
// maximum execution time in seconds (0 for no limit)
$cfg['ExecTimeLimit'] = 0;
But nothing works. Still getting error. Any help is appreciated.
First of all, are you sure you need 300 seconds of execution time? It seems rather impractical to me that a call would take 5 minutes to return an answer. I would recommend looking through your code to make sure there's no infinite loops or the likes anywhere.
Anyways, if your code is working as intended, you should check your php.ini file for another occurrence of max_execution_time which overrides yours, because the default should be at 30 seconds, and not at 300, as far as i know.
Also, you can try adding ini_set('max_execution_time', -1) at the beginning of your code. This drops the maximum execution time entirely.

openfit php fatal error database error [duplicate]

I am downloading a JSON file from an online source and and when it runs through the loop I am getting this error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\temp\fetch.php on line 24
Your loop might be endless. If it is not, you could extend the maximum execution time like this:
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
and
set_time_limit(300);
can be used to temporarily extend the time limit.
I had the same problem and solved it by changing the value for the param max_execution_time in php.ini, like this:
max_execution_time = 360 ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
max_input_time = 120 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB by default)
I hope this could help you.
All the answers above are correct, but I use a simple way to avoid it in some cases.
Just put this command in the begining of your script:
set_time_limit(0);
I ran into this problem while upgrading to WordPress 4.0. By default WordPress limits the maximum execution time to 30 seconds.
Add the following code to your .htaccess file on your root directory of your WordPress Installation to over-ride the default.
php_value max_execution_time 300 //where 300 = 300 seconds = 5 minutes
Edit php.ini
Find this line:
max_execution_time
Change its value to 300:
max_execution_time = 300
300 means 5 minutes of execution time for the http request.
Your script is timing out. Take a look at the set_time_limit() function to up the execution time. Or profile the script to make it run faster :)
if all the above didn't work for you then add an .htaccess file to the directory where your script is located and put this inside
<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>
this was the way I solved my problem , neither ini_set('max_execution_time', 86400); nor set_time_limit(86400) solved my problem , but the .htaccess method did.
We can solve this problem in 3 different ways.
1) Using php.ini file
2) Using .htaccess file
3) Using Wp-config.php file ( for Wordpress )
You can remove the restriction by seting it to zero by adding this line at the top of your script:
<?php ini_set('max_execution_time', '0'); ?>
Follow the path /etc/php5(your php version)/apache2/php.ini.
Open it and set the value of max_execution_time to a desired one.
To extend your max_execution_time you can use either ini_set or set_time_limit.
// Set maximum execution time to 10 seconds this way
ini_set('max_execution_time', 10);
// or this way
set_time_limit(10);
!! But be aware that, both functions restarts also counting of time script has already taken to execute
sleep(2);
ini_set('max_execution_time', 5);
register_shutdown_function(function(){
var_dump(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
});
for(;;);
//
// var_dump outputs float(7.1981489658356)
//
so if you want to set exact maximum amount of time script can run, your command must be very first.
Differences between those two functions are
set_time_limit does not return info whether it was successful but it will throw a warning on error.
ini_set returns old value on success, or false on failure without any warning/error
Maybe check for any thing that you have changed under the php.ini file.
For example I changed the ";intl.default_locale =" to ";intl.default_locale = en_utf8" in order to enable the "Internationalization extension (Intl)" without adding the "extension=php_intl.dll" then this same error occurred. So I suggest to check for similar mistakes.
Increase your script execution time by adding the following line at top of the PHP script.
ini_set('max_execution_time', 120); //120 seconds = 2 minutes
Reference has taken from Increase the PHP Script Execution Time
You can do it easily with WHM. Just got to:
WHM -> Service Configuration -> PHP configuration
editor-> max_execution_time=30
( 30 is default change it to whatever value u want)
set_time_limit($time_in_second); // 0 for unlimited time
I use this php function in run time if need to run a script for long.
Details here.
I have same problem in WordPress site,
I added in .htaccess file then working fine for me.
php_value max_execution_time 6000000
I have make some changes in my case in: xampp\phpMyAdmin\libraries\config.default.php
i have searched for : $cfg['ExecTimeLimit'] and change the value at right side...
You can change Right hand Value to any higher value, like '5000'. and it works.

How can I override the php.ini value of max_execution_time at runtime?

I don't have acess to php.ini in my server. I want to change the maximum execution time so that my script can runs for more than 30 seconds.
is there any way i can do that on the start of my script?
use ini_set
ini_set('max_execution_time', 300); // this will set max_execution time for 300 seconds
write this line at start of your code in php file.
OR
use this by Hanky Panky ㇱ
set_time_limit(300);

PHP- cannot change max_execution_time in xampp

I've tried everything to change the max_execution_time of a php crawler script so that it can run an infinite amount of time.
I have changed the php.ini file setting max_execution_time to 0 or 100000000 but with no change
I've also tried setting it from the php script itself by using ini_set('max_execution_time', 0);
All php scripts throw the same error Fatal error: Maximum execution time of 3000 seconds exceeded, what could I be missing and how can I make sure there is no max execution time limit?
php script
<?php
ini_set('MAX_EXECUTION_TIME', -1);
error_reporting(E_ALL); // turn on all errors, warnings and notices for easier debugging
//ini_set('max_execution_time', 123456);
ini_set('max_input_time', -1);
ini_set('memory_limit', '512M');
set_time_limit(0);
date_default_timezone_set('Europe/London');
/*code which scrapes websites*/
?>
phpinfo()
max_execution_time 0 0
max_input_time -1 -1
Try turning off safe mode in php and then try the below code
if( !ini_get('safe_mode') ){
set_time_limit(0); //this won't work if safe_mode is enabled.
}
This should allow you to run the script for infinite time.
In Apache you can change maximum execution time by .htaccess with this line
php_value max_execution_time 200
set_time_limit() php manual ref.
You shouldn't let your crawler run under apache, it's better to run it stand-alone via cli as part of a Gearman setup.
That way it won't hog your web server and it can run as long as you want. You can find many bindings for Gearman that you can use, including PHP of course.
use
set_time_limit(0);
at the top of the script
In WAMP there is three PHP.ini files so you might find 3 in xampp also, so just search for it with find and replace max_execution_time to what you are setting. But you must keep something small not too large as for speedy the app you running.
You could also try setting ignore_user_abort(TRUE); in your script as it might be the browser timing out rather than the script.
From the php.net manual
<?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);
See here for more info
http://www.php.net/manual/en/function.ignore-user-abort.php
If you are on windows, and this is a CLI run script maybe read this.
check phpinfo() from a temp script and search for max_execution_time. make sure that it has same value what you are setting. default should be 30 seconds. try to change it to a couple of different values and restart apache then check the value in phpinfo() to confirm.
if when you change the value it is reflected properly in the phpinfo() it means that there is some code in your script which is changing this value. search for two things in your code:
search your code for ini_set() and check if it is change max_execution_time
search for set_time_limit()
these functions can change maximum time limit of execution from script. otherwise you should check .htaccess from where this value may be set. but this will effect phpinfo() also.
I found the following in the xampp documentation. Maybe you are trying to edit the wrong php.ini file?
Why have changes in my php.ini no effect?
Since XAMPP 1.7.1 the "php.ini" is only in the directory "\xampp\php". Till XAMPP 1.7.0 is was in the directory "\xampp\apache\bin".
If a change in the "php.ini" have no effect, it's possible PHP is still using an other one. You can verify this with phpinfo(). Go to the URI localhost/xampp/phpinfo.php and search for "Loaded Configuration File". This value shows you the "php.ini" PHP is really using.
Info:
After changing the "php.ini" you have to restart Apache, thus Apache/PHP can read the new settings.
what you are doing is just setting the max_execution_time to whatever inside your page.
you can't change this using ini_set. you can change the memory_limit only.
see more details here...
from the php official site.
if you want them to be changed, change in php.ini.
You have to change both of these in you php.ini ( and check if that's the right php.ini by finding the location in phpinfo(); output! )
max_execution_time = 0
max_input_time = 0
And after that check if some php file is not overwriting those variables locally.
open php.ini notepad file and search or find upload_max_filesize = 1000M and you should change on Post_max_filesize = 1000M then restart your xampp and refresh the local phpmyadmin..

PHP script stops after 20-30 seconds

I'm running a script that should run for at least 30 minutes but the script stops after 30 seconds...
I'm not sure why as it worked on other server before.
Is there somewhere I need to check?
Use this:
set_time_limit(0);
ignore_user_abort(true);
ini_set('max_execution_time', 0);
You can also edit php.ini:
max_execution_time = 60; //Maximum execution time of each script, in seconds
max_input_time = 60; //Maximum amount of time each script may spend parsing request data
Hope this helps.
You might need to tweak the max_execution_time value in the php.ini file. Keep in mind that installations of PHP often keep a php.ini file for the server and one for the command line interpreter. Make sure that you edit the right one.
http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time

Categories