note 91197 added to ref.mysql
| From: | ChrisParsons at osu1 dot php dot net | Date: | Fri, 29 May 2009 15:36:42 +0000 |
| Subject: | note 91197 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156149@lists.php.net to get a copy of this message | ||
Here is a function for preventing a MySQL query timeout.
Add a temporary table to the database:
CREATE TABLE
temp_table (
ID DOUBLE ,
temp BLOB
);
Call this function in every iteration of any long loops in your code (it will only be run at a
maximum once every 15 seconds, regardless of how often the function is called):
<?php
//insert and delete something from the temp_table table to prevent a timeout
function preventMySQLTimeout()
{
static $timeoutCounter = 0;
if(time() - $timeoutCounter > 15)
{
//perform 3 types of operations to keep the connection from timing out! :-)
mysql_query("SELECT * FROM temp_table"); //SELECT
mysql_query("DELETE FROM temp_table"); //DELETE
mysql_query("INSERT INTO temp_table (temp) VALUES ('" . rand(1,200000) .
"')"); //INSERT
$timeoutCounter = time();
echo "\n<br>preventMySQLTimeout() ATTEMPT\n<br>";
}
}
?>
MySQL has multiple timeout counters, one for inserts, and one for deletes, and I could not find a
way to extend them in PHP. Please note that this is a different issue entirely than the
'connect' timeout. Every 15 seconds, this function will insert, select, and delete a row
from the temporary table, thus preventing a query timeout.
Good Luck!
----
Server IP: 208.69.120.35
Probable Submitter: 97.81.100.17
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- https://master.php.net/note/edit/91197
Del: integrated -- https://master.php.net/note/delete/91197/integrated
Del: useless -- https://master.php.net/note/delete/91197/useless
Del: bad code -- https://master.php.net/note/delete/91197/bad+code
Del: spam -- https://master.php.net/note/delete/91197/spam
Del: non-english -- https://master.php.net/note/delete/91197/non-english
Del: in docs -- https://master.php.net/note/delete/91197/in+docs
Del: other reasons-- https://master.php.net/note/delete/91197
Reject -- https://master.php.net/note/reject/91197
Search -- https://master.php.net/manage/user-notes.php