I'm using WAMP (Apache 2.2.11, MySQL 5.1.36, PHP 5.3.0) to write a PHP web application that has a link to a MySQL database.
I run a procedure that takes about 2 minutes in Toad to execute. If i try to run it in the PHP application, i got the errors "MySQL server has gone away in...", "Error reading result set's header", and "maximum execution time of 60 seconds exceeded"
I upped mysql.connect_timeout to 600 (using ini_set) and default_socket_timeout to 600 (as suggested in this question. This solved the timeout error, but i still get the first two.
I tried setting max_input_time to -1, and on the MySQL server side, i upped max_allowed_packet to 256M. Neither of these solved the problem.
Are there any other ways to bypass this error without altering the MySQL procedure being run?
when the webpage is loaded:
set_time_limit(0);
ini_set('mysql.connect_timeout', 600);//for long queries
ini_set('default_socket_timeout', 600);//for long queries
//ini_set('max_input_time',-1); //don't know what this does
when a query is called:
if($reconnect===true){
$this->disconnectDB();
}
$this->connectToDB();
if($this->selectDB($dbName)===FALSE){
return false;
}
if(mysql_ping($this->con)===false){
return array();
}
$result = mysql_query($query,$this->con); //this is where the connection "goes away"
This is the result of a PHP setting: maximum execution time of 60 seconds exceeded. Put set_time_limit(0) to disable the time limit when you need to.
MySQL server has gone away in... can be the result of several things. Including a MySQL crash. You may want to look at mysql logs for clues.
Related
How do I set the TimeOut for EXEC the Query or Stored Procedure in SqlSrv PHP
Because i am using PHP to call SQL-Server Stored Procedure.
For ex
"EXEC SP_Name"
some times its taking too long time, so the PHP page shows 500 Internal server error.
If possible to set the time limit the SP was stopped then i show the error description etc...
how do i fix this issue?
Thanks in Advance.
in your php.ini file set
max_execution_time = 60--or whatever time you wish
Refer This Link for more details
The #Jayasurya Satheesh's answer refers to the time of any php execution time, but not for db query exec time. Actually php lacks in a easy way to control the execution time of a db query.
It is more on the DB/SQL settings side. If you can define the TimeOut on the SQL Server side, this will return "timeout" to PHP.
Anyway, you can define set_time_limit(25) (where 25 is the number of seconds you want), You can put this in your php code before your SQL EXEC, not neccesary to deal with php.ini if you want to set_time_limit for specific php file. So, if the query takes more than 25 seconds, the php will stop execution.
Remember set_time_limit() does not affect other php scritps, it's only for the current file where it's placed
I am running some reports and those reports takes more than 300 seconds to execute and finally display on browser.
I have already defined the max execution time in my code and also set the same in php.ini.
ini_set('max_execution_time', 500);
I am using MySQL Workbench to monitor the execution but on 300 sec browser shows
The connection has timed out. The server at localhost is taking too long to
respond.
I just need to extend it to 400-500 sec and all of my reports will start working smoothly.
How can I do that?
Have you tried this:
ini_set('max_execution_time', 0);
This set the maximum execution time to unlimited. You could set this right before calling your report and set it back to a regular value, e.g 300 right after your report is done.
Your web server can have other Timeout configurations settings that may also interrupt PHP execution. Apache has a Timeout Directive which has default value to 300 seconds. Try changing the directive in your conf (httpd.conf for Apache) file.
For more details , See Apache Timeout Directive doc.
I've got a command-line PHP script that connects to SQL Server 2005 using an ODBC connection. It uses odbc_exec() to execute a stored procedure which may take a while to process, and I don't want it to timeout.
I've been unable to find anything in the PHP documentation regarding how to set the timeout for odbc_exec(). Does it default to an infinite wait?
There's only so much you can do here. PHP's default script execution time is set to 30 seconds. There are numerous ways to change this, including the set_time_limit() function (found in the manual), and extending execution time by using ini_set, or using odbc_setoption
//extend execution time
$num_minutes = 5;
ini_set('max_execution_time', (60*$num_minutes)); //set timeout to 5 minutes
You can also change this setting inside your php.ini file. However, all of these only control the scope within what your apache server can control. If the database itself has a timeout, it will still cut off your call and return an error, even if your personally set execution times are elevated.
According to php.net you can use odbc_setoption():
$result = odbc_prepare($conn, $sql);
odbc_setoption($result, 2, 0, 30);// 30 seconds timeout
odbc_execute($result);
So you can increase timeout to some bigger number depending on your need
All services are running (wamp icon is green) by when I try to turn on phpmyadmin I get this error. What seems to be a problem?
You can set set max execution time like #HanhNghien said in the comment with in your php.ini.
max_execution_time = 120
max_input_time = 120
But i think the better question is why need phpmyadmin so much time. Perhaps you should check your apache logs and check if there are some errors.
I fixed this with the variables section in phpmyadmin by setting an insanely high number to the timeout. It wouldn't accept '0'.
I have a long running PHP script. I am making the database connection at the very beginning of the script and does some database operation at the start up.
After that, the script perform 4 hours of PHP operation without pinging to MySQL with that connection even a single time.
At the end of these long running PHP operations, when I try to execute mysql_query it gives me the following error: MySQL Server has gone Away
Is there any possibility of increasing the connection timeout to be 4 hours? I am using PHP ADODB to connect with MySQL from my PHP application.
Please suggest what to do?
MySQL has a different timeout than PHP. You could increase it in php.ini on the line mysql.connect_timeout = 14400. Also increase the default_socket_timeout = 14400
Note that if your PHP setting allow you to do an ini_set, you can also do as follows:
ini_set('mysql.connect_timeout', 14400);
ini_set('default_socket_timeout', 14400);