How to increase maximum execution time in php [duplicate] - php

This question already has an answer here:
Increase PHP Script Execution Time [duplicate]
(1 answer)
Closed 9 years ago.
I want to increase maximum execution time in php , not by changing php.ini file.
I want to Increase it from my php file.
Is this possible?

ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
ini_set('max_execution_time', '0'); // for infinite time of execution
Place this at the top of your PHP script and let your script loose!
Taken from Increase PHP Script Execution Time Limit Using ini_set()

use below statement if safe_mode is off
set_time_limit(0);

Use the PHP function
void set_time_limit ( int $seconds )
The maximum execution time, in seconds. If set to zero, no time limit is imposed.
This function has no effect when PHP is running in safe mode. There is
no workaround other than turning off safe mode or changing the time
limit in the php.ini.

You can try to set_time_limit(n). However, if your PHP setup is running in safe mode, you can only change it from the php.ini file.

Related

Get result of a MySQL query after PHP script timeout [duplicate]

This question already has an answer here:
Increase PHP Script Execution Time [duplicate]
(1 answer)
Closed 9 years ago.
I want to increase maximum execution time in php , not by changing php.ini file.
I want to Increase it from my php file.
Is this possible?
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
ini_set('max_execution_time', '0'); // for infinite time of execution
Place this at the top of your PHP script and let your script loose!
Taken from Increase PHP Script Execution Time Limit Using ini_set()
use below statement if safe_mode is off
set_time_limit(0);
Use the PHP function
void set_time_limit ( int $seconds )
The maximum execution time, in seconds. If set to zero, no time limit is imposed.
This function has no effect when PHP is running in safe mode. There is
no workaround other than turning off safe mode or changing the time
limit in the php.ini.
You can try to set_time_limit(n). However, if your PHP setup is running in safe mode, you can only change it from the php.ini file.

Fatal error: Maximum execution time of 30 seconds exceeded. How to handle this error?

I am getting this error while running one script.
I know it's about execution time and i had went through all answers too but i want to display custom message when this error occurs so that site doesn't break.
How to handle that error as i have kept error display off on my live site so footer is not loaded due to this error which stops breaking my site?
http://whois.icann.org/en/lookup?name=google.com
When you visit this site its displaying custom error message
You can either increase the maximum execution time by using set_time_limit() or by setting max_execution_time in the php.ini.
Also by setting set_time_limit to 0 you can remove the limit for exceution time.
And if you are using linux you can try with the function register_shutdown_function.This function will be called when the execution time limit is reached.
You can try to add this line of code in the file first:
set_time_limit(0)
You can always modify your php.ini file. There is a setting for maximum execution time.
Another way is to use ini_set function.
Another way is to put the max execution time in your htaccess file.
EDIT:
The max execution time is not an error and therefore not catchable.
Please check out this: http://stackoverflow.com/questions/6861033/how-to-catch-the-fatal-error-maximum-execution-time-of-30-seconds-exceeded-in-p
Finally, there is always scope of fixing the scripts and putting lengthy processes into a queue.
you can exceed max execution time like this :
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
change below configuration in php.ini
max_execution_time = 600;
max_input_time = 120;
max_input_nesting_level = 64;
memory_limit = 128M;
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '10000');
at the first line of your php code

How to limit execution time on a php script

I'm running a php script via Linux (not via my browser) (php script.php).
Now, I want to limit the execution time to let's say 10 seconds, which means that after 10 seconds the process will shutdown by itself. How can I do that?
Already tried set_time_limit.
Already tried sleep(10); exit();
None of them made the script to shutdown.
Change the maximum execution time (in seconds) in php.ini configuration file.
max_execution_time = 7200
search in php.ini
What about using set_time_limit function? You can check documentation here
function
void set_time_limit ( int $seconds )

php Set_time_limit for a long running script [duplicate]

This question already has answers here:
Best way to manage long-running php script?
(16 answers)
Closed 9 years ago.
I have a php script that will surely take very long time to process. Is it good to have it in set_time_limit(0); I have seen some times even when we set time limit to 0 we get 500 internal server error. What is best way to handle such long time consuming script in php?
If you try to execute a long running script from the browser, you have a chance of running into all sorts of timeouts, from php, proxies, web servers and browsers. You may not be able to control all of them.
Any long running script should be run from the command line. That way you take out all of the problems except for the php execution time limit which is easy to override.
If you have access to php.ini file then set max_execution_time in it like
max_execution_time = 300
or you can user .htaccess to handle it like
php_value max_execution_time 300
Script which runs more than 360 seconds(I hope max_execution_time) will throw an Internal server error automatically even set_time_limit is applied.
You can have this in your page.
<?php
ini_set('max_input_time', time in seconds);
ini_set('max_execution_time', time in seconds);
?>
or in php.ini
set max_input_time and max_execution_time whatever you like.
or in .htaccess
php_value max_input_time 300
php_value max_execution_time 300

How do i make a Php script terminate after a fixed amout of time

How do i make a Php script terminate after a fixed amount of time
Using the max_execution_time setting in PHP.
Ie:
ini_set('max_execution_time', 30);
Would end the script after 30 seconds of execution (this is default in PHP)
You could also use:
set_time_limit(30);
See: http://php.net/manual/en/function.set-time-limit.php and http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time
I would use the set_time_limit() function which specifies the amount of time a script is allowed to run after the point at which this function has been called.
More info here

Categories