Question

I'm having loads of weird issues on Magento CE 1.7.0.2. During normal operations, the site will occasionally produce a Magento Error Page (There has been an error processing your request) on both frontend and backend. Viewing the associated report, I see the following message:

"SQLSTATE[HY000] [2006] MySQL server has gone away"

Sometimes, but more rarely, the report message will read:

 Connection reset by peer

I have looked at the var > log > system.log and the MySQL has gone away error is accompanied by the following:

Warning: PDO::__construct(): MySQL server has gone away  in /var/www/html/domain.com/live/lib/Zend/Db/Adapter/Pdo/Abstract.php on line 129
Error while reading greeting packet. PID=1863  in /var/www/html/domain.com/live/lib/Zend/Db/Adapter/Pdo/Abstract.php on line 129

In addition to this, the following error seems to be happening on every request, as well as the MySQL has gone away errors:

 Warning: include(File.php): failed to open stream: No such file or directory  in /var/www/html/domain.com/live/lib/Varien/Autoload.php on line 93
 Warning: include(): Failed opening 'File.php' for inclusion

I have looked most of the articles I can find about this and tinkered with the database parameters till the cows came home but the error remains.

After following another QnA about the compiler, I notice that the admin page System > Tools > Compilation is completely blank. I think these are all related errors but any insight into debugging or causes would be so helpful.

I apologise if this is incoherent; I've been awake for about 42 hours, so please ask for any clarification. Thank you.

-- update --

My server stack for clarity:

PHP 5.5.4 (PHP-FPM)
Nginx 1.4.2
MySQL 5.5.33

-- update --

It occurs to me (after some sleep) that I never specified - the PHP codebase and the MySQL db are on separate hardware servers - very important to know if ya'll are going to help me!! I apologise.

Was it helpful?

Solution 2

Issue resolved! Thanks to all for the help. This was a hardware firewall issue with the web host, even after they were disabled by us.

As confirmed by 1&1's server team, the hardware firewalls were correctly configured, but they were incorrectly intercepting valid traffic between the file server and the db server about 25% of the time.

We have configured iptables instead and shutdown the hardware firewalls entirely. 100% availability now.

OTHER TIPS

This is mostly due to any of the below two reasons

  1. Server timed out and closed the connection.
    fix: try increasing the wait_timeout variable in your mysqld’s my.cnf/my.ini configuration file.
  2. Server dropped an incorrect or too large packet.
    fix : increase the maximal packet size limit by increasing the value of max_allowed_packet in my.cnf/my.ini file.

Please check in files if you are trying to get something that is taking too long or inapplicable.

I experienced the same issue for Magento 2.1 and my mysql error log showed the following error multiple times during the "MySQL has gone away" process:

...[Warning] File Descriptor 1228 exceeded FD_SETSIZE=1024

To potentially resolve this issue, firstly check the open files value with $ ulimit -n, which in my case was 256.

Secondly, add table_open_cache = {that ulimit -n value} under the [mysqld] section in your my.cnf.

Now restart MySQL and hopefully you're back into the action.

Note: I'm running Magento 2.1 locally on OS X El Capitan with PHP 7.1 and MySQL 5.7.15 build with Homebrew. But I bet this solution would work on older or different setups too.

Edit the app/etc/local.xml file in your Magento folder, replacing the entry for the host to be '127.0.0.1' instead of 'localhost'.

Experienced the same error when migrating a large database between 2 servers.

Temporarily adding the following in the mysql configuration file (/etc/mysql/my.cnf) on my local (destination) server & restarting mysql (service mysql restart) fixed the problem for me:

max_allowed_packet      = 160M
wait_timeout            = 28800000

@Dexters answer worked for me.

Just to update the answer for Magento 2.3.5 (and the last few), those setting are now in app/etc/env.php instead of app/etc/local.xml

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top