MySQL "Gone Away" Error with Persistent PHP Connection

mysql workbench
mysql download
mysql free download
mysql tutorial
mysql server
how to install mysql
mysql commands
mysql online

I'm hosting a website locally on a WAMP stack. I recently switched the PHP connection to be persistent by adding array(PDO::ATTR_PERSISTENT => true) to the PDO constructor options argument. I've noticed a material drop in the response time as a result (hooray!).

The downside seems to be a gone away error when the machine wakes up. This never happened before changing the connection style.

Is it possible that the cached connection is closed, but continues to be returned? Is it possible to reset a PDO connection or reset the connection pool via PHP inside a catch block?

MySQL, The data in a MySQL database are stored in tables. A table is a collection of related data, and it consists of columns and rows. Databases are useful for storing� MySQL for OEM/ISV. Over 2000 ISVs, OEMs, and VARs rely on MySQL as their products' embedded database to make their applications, hardware and appliances more competitive, bring them to market faster, and lower their cost of goods sold.

For what it's worth I'm looking into using persistent connections on php-fpm 7.3 behind nginx and trying to reproduce that behaviour with a static pool of 1 children, and so far I can't.

I can see through SHOW PROCESSLIST on a separate terminal how the database closes the persistent connection after 5 seconds of a request that does a SELECT, but the next just opens a new one and works just as well. On the other hand if I bombard the API with a load testing tool the same connection is maintained and all requests succeed.

Maybe it was because you used Apache+mod_php instead of the php-fpm worker pool, or maybe there's been a genuine fix between PHP 5.4 and 7.3

Versions tested:

PHP-FPM: 7.3.13
mysqlnd (underlying PDO_MYSQL driver): 5.0.12-dev - 20150407
MySQL Server: 5.7.29 and 8.0.19
MariaDB Server (MySQL drop-in replacement): 10.1.43

PD thanks for laying out the reproducing steps and your thought process, it was invaluable.

PHP: MySQL Database, Oracle MySQL Database Service is a fully managed database service that enables organizations to deploy cloud native applications using the world's most � Oracle MySQL Database Service is a fully managed database service that enables organizations to deploy cloud native applications using the world’s most popular open source database. It is 100% developed, managed, and supported by the MySQL team. Fastest availability of updates, new features, and

Yes you will need to reconnect if the connection closes.

http://brady.lucidgene.com/2013/04/handling-pdo-lost-mysql-connection-error/

MySQL Database Service, MySQL is a database management system that allows you to manage relational databases. It is open source software backed by Oracle. It means you can use� MySQL is the most popular Open Source Relational SQL Database Management System. MySQL is one of the best RDBMS being used for developing various web-based software applications. MySQL is developed, marketed and supported by MySQL AB, which is a Swedish company.

What Is MySQL? & Why It Is the World's Most Popular Open Source , MySQL is the most popular Open Source Relational SQL Database Management System. MySQL is one of the best RDBMS being used for developing various� Download MySQL - Multi-user and accessible SQL server that packs the most advanced database technology that was designed for speed, scalability and reliability

MySQL Tutorial, MySQL IN 10 MINUTES (2020) | Introduction to Databases, SQL, & MySQL. 46,356 views46K Duration: 11:30 Posted: Jan 22, 2019 MySQL is an open-source relational database management system based on the SQL programming language.The primary use of MySQL databases is for online storing, but they also work for data warehousing and logging applications.

MySQL IN 10 MINUTES (2020), MySQL is the most popular open source SQL database out there, so it’s a great choice to begin your learning journey. We’ll talk a lot more about the difference between SQL and MySQL in the course, but 95% of what you learn about MySQL in this course will apply to other databases such as Postgres, Oracle, and Microsoft SQL Server.

Comments
  • My question is not if the connection needs to reconnect. I'm asking if a cached connection could timeout and then be allowed to sit inside the pool causing closed or otherwise problematic connections to be returned. The referenced post does not really address the underlying issue. The query on which I receive the gone away message is unremarkable and should return immediately so I suspect the issue isn't a timeout as much as a problem with how the connections are being managed.
  • Yes, PDO does not actively check connections status on idle connections. I don't know of any DB interface that does. It will only check it when the connection is woken. Generally, you should avoid using persistent connections unless you have considered all of the issues.