$ DbnewPDO () at the underlying layer, what is the DB instance generated? In linux, everything is a file. I think this instance should also be a file. 1. What information does this file store? Assume that the connection of {code...} DB is not active for a long time. mysql will change from... $ db = new PDO ()
What is the DB instance generated at the underlying layer?
In linux, everything is a file. I think this instance should also be a file.
1. What information does this file store?
Assume that:
$db = new PDO(...)while(true){sleep(90000) $db->xx()}
If the DB connection is not active for a long time, mysql will be automatically disconnected. After the connection is closed, the PHP request will report the MySQL server has gone away error.
2. How can I determine whether the db is disconnected before $ DB-> xx?
Reply content:
$ Db = new PDO ()
What is the DB instance generated at the underlying layer?
In linux, everything is a file. I think this instance should also be a file.
1. What information does this file store?
Assume that:
$db = new PDO(...)while(true){sleep(90000) $db->xx()}
If the DB connection is not active for a long time, mysql will be automatically disconnected. After the connection is closed, the PHP request will report the MySQL server has gone away error.
2. How can I determine whether the db is disconnected before $ DB-> xx?
What information does this file store?
I didn't find the file. The instance objects are all in the memory.
How can I determine whether the db is disconnected before $ DB-> xx?
You can throw exceptions:
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 cache can avoid the overhead of creating a new connection between each script and the database, so that the web application can be faster.
true));?>
RESOURCE
Mysql causes two interactive_timeout and wait_timeout actions.
You can extend the time by modifying the mysql configuration file/etc/my. cnf. The value is set to 10 seconds.
[Mysqld]
wait_timeout=10interactive_timeout=10
Solution:
Change the two parameters:
wait_timeout=100interactive_timeout=100
After the MySQL Server is restarted, check that the settings have taken effect.
Try it
Essentially, the connection to mysql is a commonsocket
Socket, so it is alsoFile Descriptor
. Since Yestcp
Link, so both parties have the right to disconnect the link at any time.mysql
The server defines the connection timeout time to prevent excessive connections.mysql
Resource usage.
Generallyphp
Not Requiredsleep
What?pdo
The use of objects does not require connection timeout,pdo
Will maintain everything.
if($db){ $db->xx() }
For more information, see the official documentation.
Essentially a memory buffer