ini_set for max_execution_time is not working - php

I'm using Command line of PHP with Yii Framework Command.
As I know on cli default value is 0
When I changed its value to 2 sec, it's giving 0 value that is success value as old value.
I also checked value after changing
ini_set('max_execution_time', 2);
using
echo ini_get('max_execution_time');
it's giving correct value i.e. 2
I have put tracker for getting the total execution time after that code
$scriptStartTime = time();
.....
some code
.....
echo (time() - $scriptStartTime);
It gives more than 5 sec.
Any Idea why it's not giving timeout error?

Related

Query execution was interrupted (max_statement_time exceeded)

I have run a query direct in phpmyadmin only 5 sec time taken but when load in php query than i face this error Query execution was interrupted
max_statement_time exceeded
i check the phpmyadmin and have a wrapper inside Util.php ...function .....#set_time_limit((int) $GLOBALS['cfg']['ExecTimeLimit']); ... and lead to config.values.php 'ExecTimeLimit' => 'validateNonNegativeNumber', or just in case to config.inc.php ( could be like this https://stackoverflow.com/a/13858161/5781320 ) : in my case isn't a value set you may check if in your case is!
if you do not find anything you should check php.ini "Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini " -> https://www.php.net/manual/ro/function.set-time-limit.php

PHP Script stops working after 60 seconds

I'm trying to create a form just to mess around with and I there are two sections of this form. The first input is a number to count up to and the second input is a delay interval in seconds.
I have two ways of doing this. One, is to do this client side and the other is to take the variables and send them via php. This will allow the user to leave the website and have the script still working.
The issue with this being server side is that after 60 seconds, the PHP script stops working. The form is being sent via AJAX. Here is my PHP code. I'm also on shared hosting and do not have the ability to edit PHP.ini.
$amount = $_POST["amount"];
$time = $_POST["time"];
date_default_timezone_set('America/Los_Angeles');
$x = 0;
while($x < $amount) {
echo $x;
$x++;
sleep($time);
}
echo ("Counted to " . $x);
You can use max execution time on your php file, add this line in your php file.
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
You can use set_time_limit to set the max execution time, and 0 means no time limit (not recommanded for cgi, since you web server, apache/iis still have a time limit)
and if you want to change your execution time limit of all the php scripts, you can change the setting max_execution_time in the php.ini

Getting "Maximum execution time" error intermittently

I am facing this problem, firstly I would like to say that I am very new to PHP and MySQL.
Fatal error: Maximum execution time of 30 seconds exceeded in
.........................\cdn\wished.php on line 3
I don't know what is wrong in line 3, its giving error only sometimes. Here's my code:
<?php
//wished.php
$CheckQuery = mysql_query("SELECT * FROM users WHERE ownerid='$user->id'");
$wished = 0;
while($row = mysql_fetch_assoc($CheckQuery))
{
// echo $row['fname']."<br/>";
$wished++;
}
echo $wished;
?>
It was perfect when I run this in localhost with XAMPP. As soon as I hosted my app on my domain and used their database, it start getting error.
thanks every one :)
The issue is that the SQL query is taking too long, and your production PHP configuration has the PHP script time limit set too low.
At the beginning of the script you can add more time to the PHP time limit:
http://php.net/manual/en/function.set-time-limit.php
set_time_limit(60);
for example to add 30 more seconds (or use 0 to let the PHP script continue running).
If your production database is different than your development DB (and I'm assuming production has way more data) then it might be a really expensive call to get everything from the user table.

CodeIgniter php script is not running more than 2 minutes??

I have a PHP script in my Code Igniter application,
its run on server and fetch some data but its not running more than 2 minutes approx..
and when I run this without using code igniter its works properly..what may be the reason behind this?
thanks #air4x its works . by setting set_time_limit(300) in the system/core/CodeIgniter.php
if (function_exists("set_time_limit") == TRUE AND #ini_get("safe_mode") == 0)
{
#set_time_limit(300);
}
after setting this code script running well..
Try adding this before you run your code: set_time_limit(0);
More info: http://php.net/manual/en/function.set-time-limit.php
If that doesn't work, you'll need to share what code you are running and what happens when it stops running.
There must be, Set_time_limit - Sets the maximum execution time of a script.
bool set_time_limit ( int $seconds )
When set_time_limit() called. It returns the counter to zero. In other words, if the default limit is 30 seconds, and after 25 seconds of script execution the set_time_limit(20) call is made, then the script will run for a total of 45 seconds before finishing .
Please visit http://php.net/manual/fr/function.set-time-limit.php for more information.

PHP Max Exection Timeout Notification

Is it possible to get Max Execution timeout notification so that i can use code clean up operations before the php script stops running?
Basically, i am trying to create a script that can do some changes/modifications to my database which has huge data pile. Also, this php script execution can be paused/resumed using a filelock.
You can either use set_error_handler() or register_shutdown_function().
Edit: See also: max execution time error handling
If you set 0 to set_time_limit, it will never stop :)
You can increase the limit time inside your code using:
set_time_limit(300); //time in seconds
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
or
changing the max_execution_time parameter inside your php.ini.
The default time is 30 seconds.

Categories