First, install the Handlersocket-plugin-for-mysql
Https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL
#cd Handlersocket-plugin-for-mysql
#sh./autogen.sh
#./configure--with-mysql-source=/home/jfy/soft/percona-server-5.5.18-rel23.0--with-mysql-bindir=/usr/local/ Mysql/bin--with-mysql-plugindir=/usr/local/mysql/lib/plugin
Vi/etc/my.cnf
[Mysqld]
Plugin-load=handlersocket.so (Plugin-load can be skipped)
Loose_handlersocket_port = 9998 # Specify the read request port number
# The port number to bind to (for read requests)
LOOSE_HANDLERSOCKET_PORT_WR = 9999 # Specify write request port number
# The port number to bind to (for write requests)
Loose_handlersocket_threads = 16 # Specifies the number of read threads
# The number of worker threads (for read requests)
LOOSE_HANDLERSOCKET_THREADS_WR = 1 # Specifies the number of write threads
# The number of worker threads (for write requests)
Open_files_limit = 65535
# to allow Handlersocket accept many concurren connections, make open_files_limit as large as possible.
#mysql. Server restart
#mysql
Mysql>show plugins;
| Handlersocket | ACTIVE | DAEMON | handlersocket.so | BSD |
# Netstat-an | grep 9998
TCP 0 0 0.0.0.0:9998 0.0.0.0:* LISTEN
Second, installation Php-ext-handlersocketi
Https://github.com/piteer1/php-handlersocket
#cd Php-handlersocket-master
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config
#make & make Install
#vi/usr/local/php/lib/php.ini
Extension=handlersocket.so
#php-M
Handlersocket
Third, testing
--User table
drop table IF EXISTS user;
CREATE TABLE User (
UserID char (8) binary PRIMARY key,
Username varchar (+) Comment ' user nickname ',
Feature char (+) Comment ' function ',
Siminfo char (comment) ' Sim info imsi ',
MSISDN Char (comment ' User mobile number '),
Countyrcode Char (3) Comment ' Country code ',
Zgtflag char (1) Comment ' Hong Kong Tong sign yn ',
Usertype Char (+) Comment ' user type ',
Operatorid Char (+) Comment ' operator number ',
Createtime TIMESTAMP comment ' creation time ',
PRIMARY KEY (MSISDN),
Unique index USERIDX (userid)
);
--User Account table
drop table IF EXISTS useracnt;
CREATE TABLE useracnt (
UserID char (8) binary PRIMARY key,
Activetime TIMESTAMP comment ' Activation time ',
Amount INT UNSIGNED Comment ' account amount (min) ',
Validdate Date Comment ' expiry date ',
Status char (1) Comment ' account status ',
Nextkfdate Date comment ' Next charge time '
);
<?php$host = ' localhost '; $port = 9998; $port _WR = 9999; $dbname = ' VoIP '; $table 1 = ' user '; $table 2 = ' useracnt '; try{$h S_read = new Handlersocket ($host, $port); $idx _user_r = $hs _read->createindex (1, $dbname, $table 1, ' PRIMARY ', Array (' userid ', ' Zgtflag ')); $hs _write = new Handlersocket ($host, $port _WR); $idx _useracnt_w = $hs _write->createindex (2, $dbname, $table 2, ' PRIMARY ', ' Amount ');} catch (Handlersocketexception $exception) {var_dump ($exception->getmessage ()); Die ();} Get$retval = $idx _user_r->find (' 85265101177 '); list ($userid, $zgtflag) = $retval [0];echo $userid. "\ n"; Echo $zgtflag. "\ n";//update$amount=round (0.95*100); $ret = $idx _useracnt_w->update ($userid, Array ('-? ' = $amount)); var_dump ($ret); if ($ret = = = False) {echo __line__, ': ', $index->geterror (), ': ', php_eol; Die ();} if (!is_array ($ret)) {echo "Update not found!\n"; Die ();} if (Intval ($ret [0][0]) < $amount) {echo "balance is not enough!\n"; Die ();} echo "UpDate ok!\n "; unset ($index); unset ($hs); exit;
Tested, the use of handlersocket than directly with SQL can be increased by about 0.5 times times, the test data are in InnoDB buffer
Refer to the Handlersocket protocol here:
Https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL/blob/master/docs-en/protocol.en.txt
MYSQL Handler Socket Plugin (iv) installation and use