Forum Moderators: coopster

Message Too Old, No Replies

retry query on lost connection

         

jackvull

8:23 pm on Aug 16, 2009 (gmt 0)

10+ Year Member



For one part of my code I have to write a quick query to a remote mysql database.
Occasionally, this might lose connection due to lost packets, in which case I want to retry the query.

Is there anything in PHP that can attempt a reconnect maybe 3 attempts in the next 15 seconds? It's not ideal as it's on a page where it would keep my users waiting for 15 seconds but better that it attempts the insert than me have to put it into the database at a later stage through an integrity check.

IanKelley

9:13 pm on Aug 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't know of any built in function that would do what you're looking for, you'll probably have to roll your own.

If the insert/update is not time sensitive (it's not something where the user needs to see the changed data immediately) then you might consider giving the job of inserting the data to a secondary script/process.

If you end up deciding to keep the user waiting, make sure to look at this function: [php.net...]

jackvull

1:29 pm on Aug 23, 2009 (gmt 0)

10+ Year Member



Will this do it or do I need to check for a new connection variable in the while part of the code?


//connection to remote database to check and enter the details
$squid_conn = mysql_connect("myserver",
"user",
"pw");

while (!$squid_conn) {
sleep(10);
$squid_conn = mysql_connect("myserver",
"user",
"pw");
}
mysql_select_db("mydb", $squid_conn);