Download .zip |
Info | Documentation | View files (40) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2017-06-29 (15 hours ago) | Not enough user ratings | Total: 136 This week: 13 | All time: 8,466 This week: 61 |
Version | License | PHP version | Categories | |||
zhandlesocket 1.0.5 | MIT/X Consortium ... | 5 | Networking, Zephir |
Description | Author | |||
This package can access MySQL tables as NoSQL with HandlerSocket. Innovation Award
|
Another PHP extension for communicating with handlersocket. Built with Zephir: https://github.com/phalcon/zephir. Thus, you will have to install Zephir first to build zhandlersocket. Once you have Zephir installed and cloned the zhandlersocket repo:
cd <zhandlersocket directory>
zephir build
After that, under _ext/modules_ you will find the zhandlersocket.so. Copy it to your PHP's extension_dir, add "extension=zhandlersocket.so" to your php.ini and restart your web-server. Check with the following command if zhandlersocket is there:
php -m
The output should, among other lines, contain "zhandlersocket".
use \Zhandlersocket\Client;
$client = new Client();// create a HS client with default connection parameters
$index = $client->getIndex("test", "my_table", "PRIMARY", ["id", "name"]);
// find() would return an array of rows, because an index is not always unique
// In this case, we know there will be 1 or 0 rows with ID=10, so we use findFirst(),
// which will fetch the very first row and return it
$row = $index->findFirst(10);
// Update a row:
$upd = $index->updateById(10, ["id" => 10, "name" => "New name"]);// have to specify ALL columns
HandlerSocket enables you to use InnoDB table in a NoSQL way. HS performance when selecting by Primary Key is at least close to that of Memcached, and according to some benchmarks, HS is even faster. Given this, you might well give up on using Memcached in certain cases (and having all the assiciated headaches with cache invalidating).
HS operates on InnoDB indexes. That means that you always perform a query on a index. This might be the table's PRIMARY KEY but it also may be any other index you have on the table.
In order to perform queries with ZhandlerSocket, you first need to instantiate ZhandlerSocket\Client:
$client = new Client("localhost", 9998, 9999);
Above are the default connection parameters, and you could as well omit them.
When you have a Client instance, you might want to create an instance of ZhandlerSocket\Index:
$index = $client->getIndex("test", "my_table", "PRIMARY", ["id", "name"]);
This code means that you would like to speak Handlersocket with InnoDB table my_table from database test. You will perform you find queries using PRIMARY KEY, and you would like to receive in response the foloowing columns: id and name.
PRIMARY KEY is not the only capability. Suppose you have a table movie, which has fields id, genre, title, view_count. PRIMARY KEY is id but there is also a key on genre column called genre_key. Eventually, the index might well be named exactly as the column but don't be confused: when opening a HS index, you need the index name, not the column name.
$index = $client->getIndex("test", "movie", "genre_key", ["id", "genre", "title", "view_count"]);
ZhandlerSocket\Client->getIndex() method accepts an optional 5th parameter which is filter columns. This specifies columns that you want to support additional filtering for. Those do not necessarily have to be a part of index but they have to be a part of columns you chose for selection (4th argument).
Basic usage of HS is to select a row by key, update a row, delete a row. ZhandlerSocket\Index class has the following to offer for the basic find-by-key functionality:
However, ZhandlerSocket\Index has also more to offer. HandlerSocket provides one with robust tools for quickly finding rows in a InnoDB table. Zhandlersocket ships with WhereClause class which enables you to specify criteria you want to apply to the selection.
WhereClause class is responsible for filtering and setting limits for selection from HS. HS is not only capable of selecting a single row by PRIMARY KEY, but also of selecting multiple rows based on criteria. Basic usage:
// We have an index on "counter" column, and we want to find up to 10 rows with counter > 20
$index = $client->getIndex("test", "test", "counter_idx", ["id", "counter"]);
$rows = $index->createWhereClause(">", 20)->setLimit(10)->find();
You can also perform some filtering of the results with WhereClause->addFilter(). This is _post-filtering_ which occurs on the result set obtained from index. Filtering can be done on all columns specified as fcols argument whe creating the index.
Files |
File | Role | Description | ||
---|---|---|---|---|
ext (1 file) | ||||
ide (1 directory) | ||||
test (7 files) | ||||
zhandlersocket (14 files) | ||||
.gitignore | Data | Auxiliary data | ||
config.json | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | ide | / | 0.0.1 | / | Zhandlersocket |
File | Role | Description |
---|---|---|
Client.zep.php | Class | Class source |
Command.zep.php | Class | Class source |
CommunicationException.zep.php | Class | Class source |
Connection.zep.php | Class | Class source |
ConnectionException.zep.php | Class | Class source |
DebugLogger.zep.php | Class | Class source |
DuplicateEntryException.zep.php | Class | Class source |
Encoder.zep.php | Class | Class source |
Index.zep.php | Class | Class source |
Log.zep.php | Class | Class source |
Logger.zep.php | Class | Class source |
NullLogger.zep.php | Class | Class source |
WhereClause.zep.php | Class | Class source |
WhereClauseFilter.zep.php | Class | Class source |
ZException.zep.php | Class | Class source |
Files | / | test |
File | Role | Description |
---|---|---|
BaseTest.php | Test | Test |
bootstrap.php | Conf. | Configuration script |
ClientTest.php | Test | Test |
connect.php | Conf. | Configuration script |
EncoderTest.php | Class | Class source |
IndexTest.php | Test | Test |
test.php | Aux. | Auxiliary script |
Files | / | zhandlersocket |
File | Role | Description |
---|---|---|
Client.zep | Class | Class source |
Command.zep | Class | Class source |
CommunicationException.zep | Class | Class source |
Connection.zep | Class | Class source |
ConnectionException.zep | Class | Class source |
DebugLogger.zep | Class | Class source |
DuplicateEntryException.zep | Class | Class source |
Encoder.zep | Class | Class source |
FakeLogger.zep | Class | Class source |
Index.zep | Class | Class source |
Logger.zep | Class | Class source |
WhereClause.zep | Class | Class source |
WhereClauseFilter.zep | Class | Class source |
ZException.zep | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.