php connection pooling mysql

后端 未结 6 1122
眼角桃花
眼角桃花 2020-12-02 23:55

I am planning to use MYSQL. Is there a connection pooling extension available? Or what is the normal practice for connection? Is this the one used in every where...

6条回答
  •  -上瘾入骨i
    2020-12-03 00:31

    Persistent connection support was introduced in PHP 5.3 for the mysqli extension. Support was already present in PDO MYSQL and ext/mysql. The idea behind persistent connections is that a connection between a client process and a database can be reused by a client process, rather than being created and destroyed multiple times. This reduces the overhead of creating fresh connections every time one is required, as unused connections are cached and ready to be reused.

    Unlike the mysql extension, mysqli does not provide a separate function for opening persistent connections. To open a persistent connection you must prepend p: to the hostname when connecting.

    source: http://www.php.net/manual/en/mysqli.persistconns.php

    sample code:
    $GLOBALS["mysqli"] = new mysqli('p:localhost', 'username', 'password', 'db_name');
    

    edit: Sorry for the dupe, didn't see the other answers.

提交回复
热议问题