Skip to content

The phpgibson extension provides an API for communicating with the Gibson cache server.

License

Notifications You must be signed in to change notification settings

evilsocket/phpgibson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhpGibson

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

Table of contents


  1. Installing/Configuring
  2. Classes and methods

Installing/Configuring


Everything you should need to install PhpGibson on your system.

Installation

phpize
./configure
make && make install

This extension exports a single class, Gibson.

Installation on OSX

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

Building on Windows

  1. Install visual studio 2008 (express or professional). If using visual studio 2008 express, also install the latest windows SDK.
  2. Download PHP source code
  3. Extract to C:\php\php-5.4.9
  4. Download http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip and extract to C:\php
  5. 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

Classes and methods


Usage

  1. Class Gibson

Class Gibson


Description: Creates a Gibson client

Example
$gb = new Gibson();

Connection

  1. connect - Connect to a server
  2. pconnect - Create a persistent connection or reuse a previous one if present.
  3. quit - Close the connection

connect


Description: Connects to a Gibson instance.

Parameters

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)

Return value

BOOL: TRUE on success, FALSE on error.

Example
$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.

pconnect


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.

Parameters

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)

Return value

BOOL: TRUE on success, FALSE on error.

Example
$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.

quit


Description: Disconnects from the Gibson instance.

Methods

  1. getLastError - If an error occurred, return its human readable description.
  2. set - Set the value for the given key, with an optional TTL.
  3. mset - Set the value for keys verifying the given expression.
  4. ttl - Set the TTL of a key.
  5. mttl - Set the TTL for keys verifying the given expression.
  6. get - Get the value for a given key.
  7. mget - Get the values for keys verifying the given expression.
  8. del - Delete the given key.
  9. mdel - Delete keys verifying the given expression.
  10. inc - Increment by one the given key.
  11. minc - Increment by one keys verifying the given expression.
  12. mdec - Decrement by one the given keys.
  13. dec - Decrement by one keys verifying the given expression.
  14. lock - Prevent the given key from being modified for a given amount of seconds.
  15. mlock - Prevent keys verifying the given expression from being modified for a given amount of seconds.
  16. unlock - Remove the lock on a given key.
  17. munlock - Remove the lock on keys verifying the given expression.
  18. count - Count items for a given expression.
  19. meta - Obtain a specific information about a given item.
  20. stats - Get system stats about the Gibson instance.
  21. keys - Return a list of keys matching the given prefix.
  22. ping - Ping the server instance to refresh client last seen timestamp.

getLastError


Description: If an error occurred, return its human readable description.

Parameters

None.

Return value

string: The error description.

Example
echo $gibson->getLastError();

set


Description: Set the value for the given key, with an optional TTL.

Parameters

key (string) The key to set. value (string) The value. ttl (int) The optional ttl in seconds.

Return value

Mixed The string value itself in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', 'bar' );
$gibson->set( 'foo2', 'bar2', 2 ); // 2 seconds TTL

mset


Description: Set the value for keys verifying the given expression.

Parameters

key (string) The key prefix to use as expression. value (string) The value.

Return value

Mixed The integer number of updated items in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', 'bar' );
$gibson->set( 'fuu', 'rar' );

$gibson->mset( 'f', 'yeah' );

ttl


Description: Set the TTL of a key.

Parameters

key (string) The key. ttl (integer) The TTL in seconds.

Return value

BOOL TRUE in case of success, FALSE in case of failure.

Example
$gibson->ttl( 'foo', 3600 ); // 1 hour TTL

mttl


Description: Set the TTL for keys verifying the given expression.

Parameters

key (string) The key prefix to use as expression. ttl (integer) The TTL in seconds.

Return value

Mixed The integer number of updated items in case of success, FALSE in case of failure.

Example
$gibson->mttl( 'f', 3600 ); // 1 hour TTL for every f* key.

get


Description: Get the value for a given key.

Parameters

key (string) The key to get.

Return value

Mixed An integer or string value (depends on item encoding) in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', 'bar' );
$gibson->get( 'foo' ); 

mget


Description: Get the value for a given key.

Parameters

key (string) The key prefix to use as expression.

Return value

Mixed An array of key => value items in case of success, FALSE in case of failure.

Example
$gibson->mget( 'f' ); 

del


Description: Delete the given key.

Parameters

key (string) The key to delete.

Return value

BOOL TRUE in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', 'bar' );
$gibson->del( 'foo' ); 

mdel


Description: Delete keys verifying the given expression.

Parameters

key (string) The key prefix to use as expression.

Return value

Mixed The integer number of deleted items in case of success, FALSE in case of failure.

Example
$gibson->mdel( 'f' ); // Delete every f* key.

inc


Description: Increment by one the given key.

Parameters

key (string) The key to increment.

Return value

Mixed The incremented integer value in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', '1' );
$gibson->inc( 'foo' ); 

minc


Description: Increment by one keys verifying the given expression.

Parameters

key (string) The key prefix to use as expression.

Return value

Mixed The integer number of incremented items in case of success, FALSE in case of failure.

Example
$gibson->minc( 'f' ); // Increment by one every f* key.

dec


Description: Decrement by one the given key.

Parameters

key (string) The key to decrement.

Return value

Mixed The decremented integer value in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', '1' );
$gibson->dec( 'foo' ); 

mdec


Description: Decrement by one keys verifying the given expression.

Parameters

key (string) The key prefix to use as expression.

Return value

Mixed The integer number of decremented items in case of success, FALSE in case of failure.

Example
$gibson->mdec( 'f' ); // Decrement by one every f* key.

lock


Description: Prevent the given key from being modified for a given amount of seconds.

Parameters

key (string) The key. time (integer) The time in seconds to lock the item.

Return value

BOOL TRUE in case of success, FALSE in case of failure.

Example
$gibson->lock( 'foo', 3600 ); // 1 hour lock

mlock


Description: Prevent keys verifying the given expression from being modified for a given amount of seconds.

Parameters

key (string) The key prefix to use as expression. ttl (integer) The lock period in seconds.

Return value

Mixed The integer number of locked items in case of success, FALSE in case of failure.

Example
$gibson->mlock( 'f', 3600 ); // 1 hour lock for every f* key.

unlock


Description: Remove the lock from the given key.

Parameters

key (string) The key.

Return value

BOOL TRUE in case of success, FALSE in case of failure.

Example
$gibson->unlock( 'foo' ); // foo now is unlocked

munlock


Description: Remove the lock on keys verifying the given expression.

Parameters

key (string) The key prefix to use as expression.

Return value

Mixed The integer number of unlocked items in case of success, FALSE in case of failure.

Example
$gibson->munlock( 'f' ); // Every f* key is now unlocked.

count


Description: Count items for a given expression.

Parameters

key (string) The key prefix to use as expression.

Return value

Mixed The integer count of items in case of success, FALSE in case of failure.

Example
$gibson->count( 'f' ); // Count every f* key

meta


Description: Obtain a specific information about a given item.

Parameters

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.
Return value

Mixed An integer with the value in case of success, FALSE in case of failure.

Example
$gibson->set( 'foo', 'bar' );

echo $gibson->meta( 'foo', 'created' )."\n"; // will print the actual timestamp

stats


Description: Get system stats about the Gibson instance.

Parameters

None

Return value

Mixed An array of key => value items in case of success, FALSE in case of failure.

Example
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
)

keys


Description: Return a list of keys matching the given prefix.

Parameters

prefix (string) The key prefix to use as expression.

Return value

Mixed The list of matching keys, FALSE in case of failure.

Example
$gibson->set( 'app:count:a', 1 );
$gibson->set( 'app:count:b', 2 );

$gibson->keys( 'app:count:' ); // Will return an array with both keys.

ping


Description: Ping the server instance to refresh client last seen timestamp.

Parameters

None

Return value

BOOL TRUE in case of success, FALSE in case of failure.

Example
$gibson->ping(); 

About

The phpgibson extension provides an API for communicating with the Gibson cache server.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages