1

Hey everyone this issue is giving me gray hair, last week this was all working fine, Monday when I get into work and try running another test it starts failing.

Backround: I am building a utility for work that will allow the video guys to either upload a file from their system or specify the URL of a video whether it be in Amazon S3 or wherever. The utility will then either upload the video store it and put an entry in the DB to keep track of it, or move it from the URL provided to the dir they are being stored in and do the same with the mysql.

The Issue: It has recently became an issue where when moving from a URL I get an error stating that the "MySQL Server has gone away" lots of searching has ended up with lots of issues on timeouts, packet size etc. But, the MySQL connection isn't even being opened until after the file has been moved into its directory. When moving a file from a URL I get the error in under 10 seconds. The only tests I can get to go through is when I specify a URL of a file that is really small, like 5mb.

Last week I was able to run successful tests on files up over 500mb (pulling from URL). Now the files will still move over, but I get the server has gone away error.

Here is the code I am using

file_put_contents('vid_bin/'.$fName, fopen($url, 'r'));
$qry = "INSERT INTO videos (".$fields.") VALUES (".$vals.")";
$db = new mydb;
$db->mydb; //connects
$db->select_db("thedbname"); //selects db
$db->query($qry); //runs query
if($db->error) {
    die($db->error . "\n". $qry); //oh noes
} else {
    ...
}

Our server guy hasn't been available so I am left wondering if its my code or if its something that changed on the server. I am pretty sure its not the code but wanted outside opinions on what could be causing MySQL to freak out despite only having strings, dates and ints stored in it.

UPDATE: If I process the MySQL bits before messing with the file all works well. The problem is, I have the file handling bit of code in a try/catch because if someone provides an invalid URL or something goes haywire I don't want to go back and remove the MySQL record.

Any idea why MySQL would care if the file is handled before it? I was thinking it might have something to do with packet size in the MySQL config but I am not storing the file in the db. Looks like it is going to be an issue for the Server admin to handle, unless someone has some insight into why this would be happening from the code end of things.

JustinM151
  • 744
  • 3
  • 11
  • Are you sure you're connecting? If your constructor doesn't connect when you instantiate, I don't think this line is doing it: $db->mydb; I would imagine that needs to be $db->mydb(); – Jage Dec 03 '13 at 18:44
  • Check http://stackoverflow.com/questions/1468579/php-mysqli-reconnect-problem maybe it will help you, setting reconnect=ON and using ping function – Iłya Bursov Dec 03 '13 at 18:45
  • @Jage it is indeed connecting, The missing () were innocent casualties when pulling out my connection info. – JustinM151 Dec 03 '13 at 19:02
  • @Ilya Bursov - Where would I want to tell it to reconnect? It doesn't open the connection until after the file is done downloading/moving, and after the MySQL finishes its query the page dies with a JSON response for the interface's AJAX to handle. the whole process takes about 5 seconds or less for files in the 20mb range. I would literally have to connect, then ping/reconnect on the next line. – JustinM151 Dec 03 '13 at 19:03
  • @JustinM151 reconnect should be configured in php.ini, other - read whole thread via link I've posted, there can be more options/problems – Iłya Bursov Dec 03 '13 at 19:40

2 Answers2

0

Ends up nothing was changed on the server so I'm not sure why the code stopped working as intended. I just handle the MySQL stuff first, then the file. There is a cron that then does some work on the files based on the SQL results so I just added in a check that the file exists and if it doesn't I remove the record. Not exactly how I wanted it to operate but gets the job done.

JustinM151
  • 744
  • 3
  • 11
0

increase max_allowed_packet in mysql to 128MB

hamed
  • 1