RTphp is looking for a suitable connection pool. Is pdo supported? RT php is looking for a suitable connection pool? Is pdo supported?
Reply content:
RT php is looking for a suitable connection pool. Is pdo supported?
PHP does not support connection. PHP connects to the database very quickly (which is much faster than the database connection method in other languages). Generally, you can use direct connection. pdo supports connection pools.
-
Not Supported
-
There is an option for you to enable persistent connections. However, you will find that a large number of server connections are not released at that time, so it is not recommended. If you are interested, try it.
$dbh = new PDO('mysql:host=xxx;port=xxx;dbname=xxx', 'xxx', 'xxx', array( PDO::ATTR_PERSISTENT => true));
The program uses a persistent connection (PDO: ATTR_PERSISTENT) to access the database, then a PHP-FPM worker corresponds to a persistent connection to MySQL.
After the request ends, PHP will not release the connection to MySQL for reuse next time. This process is transparent to the program.
This can be seen as a "database connection pool" maintained by the PHP-FPM ".
If your server has 12 cores (hyper-threading), you open 24 PHP-FPM worker processes. note that the number of processes in the PHP-FPM is pm. max_children should not exceed the maximum number of connections of MySQL max_connections (151 by default ).
'127.0.0.1', 'db_username' => 'root', 'db_password' => '', 'db_name' => 'mybase', 'db_port' => 3306, 'db_pconnect' => true);$dsn = "mysql:dbname=$app[db_name];host=$app[db_host];port=$app[db_port];charset=utf8";$db = new PDO($dsn, $app['db_username'], $app['db_password'], array( PDO::ATTR_PERSISTENT => $app['db_pconnect'], PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
Mysql proxy is used in the connection pool.
AvailableswooleExtension.
For details, refer to swoole extension to implement a real PHP database connection pool.
Add ODBC to PDO.