Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: MySQL server has gone away

Tags:

php

mysql

I know this question has been asked numerous times but I've tried everything.

I have a PHP script that iterates through thousands of images, performs resizing if necessary and then inserts into the database.

I'm getting this error message:

Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\Utilities\server\htdocs\newGen\index.php on line 105

Warning: mysql_query() [function.mysql-query]: Error reading result set's header in C:\Utilities\server\htdocs\newGen\index.php on line 105

I'm using Xampplite and so some parts of the php.ini are missing that others have used to solve the problem because they're not using the lite version.

I'm certain the problem is not timeouts. While the script will run for several minutes it skips over images that have already been processed and so I quickly get the error message within about 10 seconds. Maybe this has something to do with max table size? I can't find anything in my php.ini that controls this.

All help is greatly appreciated, I've been going at this for hours now.

EDIT:

Here is the code at the 105 mark, it's the query:

        // Add tNail and image to db
        mysql_query("INSERT INTO gallery values('','$hash','$thumbBlob','$imageBlob','$type','','0','0.0')");
    //  $q->execute();
        print "Successfully processed $fileName<br>";

As you can see by the comments I tried PDO with this and got the same error, foolishly I thought going back to mysql_ commands would help.

If it's of any help the script complains at the same image every time, yet each image is only ever a few tens of kilobytes and a couple hundred at the most.

like image 609
Lee Avatar asked Jul 20 '12 16:07

Lee


People also ask

How do I fix MySQL server has gone in PHP?

To fix, you can increase the maximal packet size limit max_allowed_packet in my. cnf file, eg. set max_allowed_packet = 128M , then restart your MySQL server: sudo /etc/init. d/mysql restart.

Why MySQL server has gone away?

The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. In this case, you normally get one of the following error codes (which one you get is operating system-dependent). The client couldn't send a question to the server.

Can not reconnect to MySQL after 1 attempt's ): MySQL server has gone away?

The MySQL server has gone away error, means that MySQL server (mysqld) timed out and closed the connection. By default, MySQL will close connections after eight hours (28800 seconds) if nothing happens.


1 Answers

Check the value of "max_allowed_packet" in your my.cnf MySQL config file.

like image 72
LSerni Avatar answered Oct 01 '22 12:10

LSerni