php-handlersocket

    技术2026-05-09  2

    Summary

    This extension provide API for communicating with HandlerSocket plugin for MySQL.

    libhsclient binding for PHP.

    notice

    It may be defective for a test version.

    Installation

    required to compile the libhsclient.

    $ phpize$ ./configure$ make# make install

    A successful install will have created handlersocket.so and put it into the PHP extensions directory. You'll need to and adjust php.ini and add an extension=handlersocket.so line before you can use the extension.

    Class synopsis

    HandlerSocket {    /* Constants */    const HandlerSocket::PRIMARY;    /* Methods */    __construct  ( string $host, int $port, [ array $options ])    public bool openIndex ( int $id, string $db, string $table, string $index, string $fields )    public mixed executeSingle ( int $id, string $op, array $fields [, int $limit, int $skip, strint $modop, array $values ] )    public mixed executeMulti ( array $requests )    public int executeUpdate ( int $id, string $op, array $fields, array $values [, int $limit, int $skip ] )    public int executeDelete ( int $id, string $op, array $fields [, int $limit, int $skip ] )    public bool executeInsert ( int $id, array $values )    public string getError ( void )}

    Example

    <?php$host = 'localhost';$port = 9998;$port_wr = 9999;$dbname = 'hstestdb';$table = 'hstesttbl';//GET$hs = new HandlerSocket($host, $port);if (!($hs->openIndex(1, $dbname, $table, HandlerSocket::PRIMARY, 'k,v'))){    echo $hs->getError(), PHP_EOL;    die();}$retval = $hs->executeSingle(1, '=', array('k1'), 1, 0);var_dump($retval);$retval = $hs->executeMulti(    array(array(1, '=', array('k1'), 1, 0),          array(1, '=', array('k2'), 1, 0)));var_dump($retval);unset($hs);//UPDATE$hs = new HandlerSocket($host, $port_wr);if (!($hs->openIndex(2, $dbname, $table, '', 'v'))){    echo $hs->getError(), PHP_EOL;    die();}if (!($hs->executeUpdate(2, '=', array('k1'), array('V1'), 1, 0))){    echo $hs->getError(), PHP_EOL;    die();}unset($hs);//INSERT$hs = new HandlerSocket($host, $port_wr);if (!($hs->openIndex(3, $dbname, $table, '', 'k,v'))){    echo $hs->getError(), PHP_EOL;    die();}if (!($hs->executeInsert(3, array('k2', 'v2')))){    echo $hs->getError(), PHP_EOL;}if (!($hs->executeInsert(3, array('k3', 'v3')))){    echo 'A', $hs->getError(), PHP_EOL;}if (!($hs->executeInsert(3, array('k4', 'v4')))){    echo 'B', $hs->getError(), PHP_EOL;}unset($hs);//DELETE$hs = new HandlerSocket($host, $port_wr);if (!($hs->openIndex(4, $dbname, $table, '', ''))){    echo $hs->getError(), PHP_EOL;    die();}if (!($hs->executeDelete(4, '=', array('k2')))){    echo $hs->getError(), PHP_EOL;    die();}

    最新回复(0)