Problems with the PHP connection pool ____php

Source: Internet
Author: User
Tags connection pooling ibm db2 pconnect php script sybase
PHP Connection Pool issues & Load BalancingProblems with the PHP connection pool:
The PHP script itself does not do the connection pool, because the PHP script will release all the memory resources after the interpretation, of course, the database connection will be released, but some middleware can also be used as a connection pool, as long as the relevant PHP to provide the driver, so you can do their own PHP connection pool, But it's definitely not a 100% pure PHP connection pool. Mysql_pconnect is an analog connection pool built in PHP, but it is not implemented with PHP scripts.   But once a request can reuse links, reduce the cost of new. Single-row mode <?php        class ConnecToDB         {              private static   $instance =array ();            //Prevent external creation of new database connection classes             private function _constuct () {}             static public function  Connect ()             {                     //Connection class is not 100, create new class          &Nbsp;       if (Count (self:: $instance) <100)                  {                      $newDb =new self ();                     self::$ instance[]= $newDb;                     return  $newDb:: Condb ();                 }                 else                 {                         //random number to ensure database connection equalization                       $i =rand (0,99);                      $new _obj=self:: $instance [$i];                     return  $new _obj:: Condb ();                }             }             static private function condb ()              {                 try                {    &NBSP;&NBSP;&NBSP;               $connec =mysql_connect (" "," Database Account "," Database Password ";                     mysql_select_db ("database name");//Select Database                         }                 catch (exception  $e)                  {                      $errors []= $e->getmessage ();                  &nbsp}            &NBSP;&NB Sp

The main purpose of the connection pool is to save time to open the database. The connection pooling mechanism opens up n database connections in advance, caches them, and saves time by using these open connections directly when you need to use the database. The presence of a connection pool basically eliminates the time and CPU overhead of a database connection being disconnected.
Connection Pooling Solution:
1, Pconnect (persistent connection): the principle of pconnect, and connection pool is similar to the program to close the connection, but PHP does not really shut down, open again, directly using the available connections.
If the amount of traffic is too large, MySQL should configure the MySQL database service in the my.cnf of the max_connection value, such as Max_connections = 2000.
2, MySQL proxy.
3. Memcache: A database cache implementation for MySQL.
4, SQL Relay: An open source database pool connection Proxy server. Supports Oracle, MySQL, mSQL, PostgreSQL, Sybase, MS SQL Server, IBM DB2, Sybase, SQLite, Lago, ODBC, MS Access, and more.
installation and configuration [SQL SERVER] (, install SQL relay need to install Rudiments first:
1, Installation rudiments:
# tar Vxzf rudiments-0.28.2.tar.gz
# CD rudiments-0.28.2
# make
# make Install
2. Install SQL Relay:
# tar Vxzf sqlrelay-0.36.4.tar.gz
# CD sqlrelay-0.36.4
#./configure--prefix=/usr/local/sqlrelay--with-rudiments-prefix=/usr/local/rudiments--with-mysql-prefix= MySQL installation path--with-freetds-prefix=freetds installation path--with-oracle-home=oracle installation path--with-php-prefix=php installation path
# make
# make Install
3, set PHP: Modify php.ini Extension_dir = "./", change the above content to: Extension_dir = "/usr/local/php/lib/php/extensions/ no-debug-non-zts-20050922 ".
According to the path of the PHP installation to modify, not every version of PHP is this path, add the following content in the PHP.ini
4, modify the SQL relay configuration file
# CP Sqlrelay.conf.example sqlrelay.conf
Change the contents of sqlrelay.conf to:
<?xml version= "1.0"?>
<instance id= "Msdetest" port= "9000" socket= "/tmp/msdetest.socket" dbase= "FreeTDS" connections= "5" maxconnections= "Ten" maxqueuelength= "0" growby= "1" ttl= "endofsession=" Commit "sessiontimeout=" 5 "runasuser=" Nobody "runasgroup=" Nobody "cursors=" 5 "authtier=" Listener "handoff=" pass ">
<user user= "sa" password= "sa"/>
<connection connectionid= "Msdetest" string= "Server=msde;db=pubs;user=sa;password=sa" metric= "1"/>
Start the SQL Relay and test;
1. Start SQL Relay
# Export path= $PATH:/usr/local/sqlrelay/bin
# Sqlr-start-id Msdetest
2. Use SQL tools:

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