$db = new PDO ()
At the bottom, what is the generated DB instance, exactly?
Under Linux Everything under the document concept, I think, this instance should also be a file.
1. What information is stored in this file?
Suppose such a scenario:
$db = new PDO(...)while(true){sleep(90000) $db->xx()}
DB connection is inactive for a long time, MySQL will automatically disconnect, after disconnecting, PHP to request will report MySQL server has gone away error.
2, how to judge before $db->xx () This db has been disconnected?
Reply content:
$db = new PDO ()
At the bottom, what is the generated DB instance, exactly?
Under Linux Everything under the document concept, I think, this instance should also be a file.
1. What information is stored in this file?
Suppose such a scenario:
$db = new PDO(...)while(true){sleep(90000) $db->xx()}
DB connection is inactive for a long time, MySQL will automatically disconnect, after disconnecting, PHP to request will report MySQL server has gone away error.
2, how to judge before $db->xx () This db has been disconnected?
What information does this file hold?
I didn't find the file either, the instance object is in memory.
How can I tell if this db has been disconnected before $db->xx ()?
You can use exceptions to throw:
query('SELECT * from FOO') as $row) { print_r($row); } $dbh = null;} catch (PDOException $e) { print "Error!: " . $e->getMessage() . "
"; die();}?>
PHP provides persistent connections
Persistent connection caching avoids the overhead of creating a new connection each time the script needs to respond to the database, making the Web application faster.
true));?>
RESOURCE
MySQL causes this behavior where there are two interactive_timeout, wait_timeout
You can extend the time by modifying the MySQL configuration file/etc/my.cnf. This is set for 10 seconds.
[Mysqld]
wait_timeout=10interactive_timeout=10
The workaround is to:
Change these two parameters to:
wait_timeout=100interactive_timeout=100
After restarting MySQL server entry, the view settings are in effect.
You give it a try.
Essentially, the link to MySQL is a common to socket
socket, so it's also a File Descriptor
. Since it is a link tcp
, the link between the two parties has the right to disconnect at any time, as the big God Upstairs said, this is generally defined by the mysql
server link timeout time, this is to prevent excessive links caused by mysql
resource consumption.
In general php
, what is not required sleep
, normal use of the pdo
object does not take into account the link timeout, pdo
will maintain everything.
if($db){ $db->xx() }
All documents, refer to official documentation, general knowledge
Essentially a piece of memory buffer