I have a script that I run every night. This script reads an XML feed which pulls from a MS SQL database and then updates a MySQL database.

The XML feed is rather large and the server where the XML feed comes from is rather slow.

I’m not the only one who thinks so – cURL kept timing out waiting for the XML feed to load. I had to increase the cURL timeout option:

curl_setopt($curl, CURLOPT_TIMEOUT, 120);

I finally got the XML feed to load properly, but then I started getting errors with my MySQL queries:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mypath/myscript.php on line 30

I looked and looked for the error in my select statement and in my mysql_num_rows function call. These calls had worked just fine in my test code.

The next error gave me more clues:

MySQL server has gone away

After a little research, I found that this error is thrown when your database connection times out. Now, I’ve moved my database connect string below my xml load function. Hopefully, waiting until after the large xml file is loaded will keep my connection from timing out.

Maybe tonight my database won’t disappear again!

Leave a Comment

Your email address will not be published. Required fields are marked *