The phpgibson extension provides an API for communicating with the Gibson cache server. It is released under the BSD License. This code has been developed and maintained by Simone Margaritelli.
You can send comments, patches, questions here on github or to evilsocket@gmail.com (@evilsocket).
Everything you should need to install PhpGibson on your system.
phpize
./configure
make && make install
This extension exports a single class, Gibson.
If the install fails on OSX, type the following commands in your shell before trying again:
MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
If that still fails and you are running Zend Server CE, try this right before "make": ./configure CFLAGS="-arch i386"
.
- Install visual studio 2008 (express or professional). If using visual studio 2008 express, also install the latest windows SDK.
- Download PHP source code
- Extract to C:\php\php-5.4.9
- Download http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip and extract to C:\php
- In cmd.exe
- cd C:\php\php-5.4.9\ext
- git clone https://github.com/evilsocket/phpgibson.git
- cd ..
- buildconf.js
- "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv" /x86 /xp /release
- path "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin";%PATH%
- bin\phpsdk_setvars.bat
- "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
- configure.js --disable-all --enable-cli --enable-gibson
- nmake php_gibson.dll
- fix any compilation errors
Description: Creates a Gibson client
$gb = new Gibson();
- connect - Connect to a server
- pconnect - Create a persistent connection or reuse a previous one if present.
- quit - Close the connection
Description: Connects to a Gibson instance.
host: string. can be a host, or the path to a unix domain socket
port: int, optional
timeout: float, value in milli seconds (optional, default is 0 meaning unlimited)
BOOL: TRUE
on success, FALSE
on error.
$gibson->connect('127.0.0.1', 10128);
$gibson->connect('127.0.0.1'); // port 10128 by default
$gibson->connect('127.0.0.1', 10128, 200); // 200 ms timeout.
$gibson->connect('/tmp/gibson.sock'); // unix domain socket.
Description: Create a persistent connection or reuse a previous one if present. If a previous connection exists but is not valid ( timed out, disconnected, etc ) the connection will be enstablished again.
host: string. can be a host, or the path to a unix domain socket
port: int, optional
timeout: float, value in milli seconds (optional, default is 0 meaning unlimited)
BOOL: TRUE
on success, FALSE
on error.
$gibson->pconnect('127.0.0.1', 10128);
$gibson->pconnect('127.0.0.1'); // port 10128 by default
$gibson->pconnect('127.0.0.1', 10128, 200); // 200 ms timeout.
$gibson->pconnect('/tmp/gibson.sock'); // unix domain socket.
Description: Disconnects from the Gibson instance.
- getLastError - If an error occurred, return its human readable description.
- set - Set the value for the given key, with an optional TTL.
- mset - Set the value for keys verifying the given expression.
- ttl - Set the TTL of a key.
- mttl - Set the TTL for keys verifying the given expression.
- get - Get the value for a given key.
- mget - Get the values for keys verifying the given expression.
- del - Delete the given key.
- mdel - Delete keys verifying the given expression.
- inc - Increment by one the given key.
- minc - Increment by one keys verifying the given expression.
- mdec - Decrement by one the given keys.
- dec - Decrement by one keys verifying the given expression.
- lock - Prevent the given key from being modified for a given amount of seconds.
- mlock - Prevent keys verifying the given expression from being modified for a given amount of seconds.
- unlock - Remove the lock on a given key.
- munlock - Remove the lock on keys verifying the given expression.
- count - Count items for a given expression.
- meta - Obtain a specific information about a given item.
- stats - Get system stats about the Gibson instance.
- keys - Return a list of keys matching the given prefix.
- ping - Ping the server instance to refresh client last seen timestamp.
Description: If an error occurred, return its human readable description.
None.
string: The error description.
echo $gibson->getLastError();
Description: Set the value for the given key, with an optional TTL.
key (string) The key to set. value (string) The value. ttl (int) The optional ttl in seconds.
Mixed The string value itself in case of success, FALSE
in case of failure.
$gibson->set( 'foo', 'bar' );
$gibson->set( 'foo2', 'bar2', 2 ); // 2 seconds TTL
Description: Set the value for keys verifying the given expression.
key (string) The key prefix to use as expression. value (string) The value.
Mixed The integer number of updated items in case of success, FALSE
in case of failure.
$gibson->set( 'foo', 'bar' );
$gibson->set( 'fuu', 'rar' );
$gibson->mset( 'f', 'yeah' );
Description: Set the TTL of a key.
key (string) The key. ttl (integer) The TTL in seconds.
BOOL TRUE
in case of success, FALSE
in case of failure.
$gibson->ttl( 'foo', 3600 ); // 1 hour TTL
Description: Set the TTL for keys verifying the given expression.
key (string) The key prefix to use as expression. ttl (integer) The TTL in seconds.
Mixed The integer number of updated items in case of success, FALSE
in case of failure.
$gibson->mttl( 'f', 3600 ); // 1 hour TTL for every f* key.
Description: Get the value for a given key.
key (string) The key to get.
Mixed An integer or string value (depends on item encoding) in case of success, FALSE
in case of failure.
$gibson->set( 'foo', 'bar' );
$gibson->get( 'foo' );
Description: Get the value for a given key.
key (string) The key prefix to use as expression.
Mixed An array of key => value items in case of success, FALSE
in case of failure.
$gibson->mget( 'f' );
Description: Delete the given key.
key (string) The key to delete.
BOOL TRUE
in case of success, FALSE
in case of failure.
$gibson->set( 'foo', 'bar' );
$gibson->del( 'foo' );
Description: Delete keys verifying the given expression.
key (string) The key prefix to use as expression.
Mixed The integer number of deleted items in case of success, FALSE
in case of failure.
$gibson->mdel( 'f' ); // Delete every f* key.
Description: Increment by one the given key.
key (string) The key to increment.
Mixed The incremented integer value in case of success, FALSE
in case of failure.
$gibson->set( 'foo', '1' );
$gibson->inc( 'foo' );
Description: Increment by one keys verifying the given expression.
key (string) The key prefix to use as expression.
Mixed The integer number of incremented items in case of success, FALSE
in case of failure.
$gibson->minc( 'f' ); // Increment by one every f* key.
Description: Decrement by one the given key.
key (string) The key to decrement.
Mixed The decremented integer value in case of success, FALSE
in case of failure.
$gibson->set( 'foo', '1' );
$gibson->dec( 'foo' );
Description: Decrement by one keys verifying the given expression.
key (string) The key prefix to use as expression.
Mixed The integer number of decremented items in case of success, FALSE
in case of failure.
$gibson->mdec( 'f' ); // Decrement by one every f* key.
Description: Prevent the given key from being modified for a given amount of seconds.
key (string) The key. time (integer) The time in seconds to lock the item.
BOOL TRUE
in case of success, FALSE
in case of failure.
$gibson->lock( 'foo', 3600 ); // 1 hour lock
Description: Prevent keys verifying the given expression from being modified for a given amount of seconds.
key (string) The key prefix to use as expression. ttl (integer) The lock period in seconds.
Mixed The integer number of locked items in case of success, FALSE
in case of failure.
$gibson->mlock( 'f', 3600 ); // 1 hour lock for every f* key.
Description: Remove the lock from the given key.
key (string) The key.
BOOL TRUE
in case of success, FALSE
in case of failure.
$gibson->unlock( 'foo' ); // foo now is unlocked
Description: Remove the lock on keys verifying the given expression.
key (string) The key prefix to use as expression.
Mixed The integer number of unlocked items in case of success, FALSE
in case of failure.
$gibson->munlock( 'f' ); // Every f* key is now unlocked.
Description: Count items for a given expression.
key (string) The key prefix to use as expression.
Mixed The integer count of items in case of success, FALSE
in case of failure.
$gibson->count( 'f' ); // Count every f* key
Description: Obtain a specific information about a given item.
key (string) The key of the value to search. field (string) The information name to retrieve, allowed values follow.
- size The size in bytes of the item value.
- encoding The value encoding.
- access Timestamp of the last time the item was accessed.
- created Timestamp of item creation.
- ttl Item specified time to live, -1 for infinite ttl.
- left Number of seconds left for the item to live if a ttl was specified, otherwise -1.
- lock Number of seconds the item is locked, -1 if there's no lock.
Mixed An integer with the value in case of success, FALSE
in case of failure.
$gibson->set( 'foo', 'bar' );
echo $gibson->meta( 'foo', 'created' )."\n"; // will print the actual timestamp
Description: Get system stats about the Gibson instance.
None
Mixed An array of key => value items in case of success, FALSE
in case of failure.
print_r( $gibson->stats() );
Output:
Array
(
[server_started] => 1369857026
[server_time] => 1369857149
[first_item_seen] => 1369857132
[last_item_seen] => 1369857132
[total_items] => 1
[total_compressed_items] => 0
[total_clients] => 1
[total_cron_done] => 1228
[memory_used] => 1772
[memory_peak] => 1772
[item_size_avg] => 1772
)
Description: Return a list of keys matching the given prefix.
prefix (string) The key prefix to use as expression.
Mixed The list of matching keys, FALSE
in case of failure.
$gibson->set( 'app:count:a', 1 );
$gibson->set( 'app:count:b', 2 );
$gibson->keys( 'app:count:' ); // Will return an array with both keys.
Description: Ping the server instance to refresh client last seen timestamp.
None
BOOL TRUE
in case of success, FALSE
in case of failure.
$gibson->ping();