Does phppdo support connection pools?

Source: Internet
Author: User
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.

  1. Not Supported

  2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.