<commit_before># PhpGibson

The phpgibson extension provides an API for communicating with the [Gibson](http://gibson-db.in/) cache server. It is released under the BSD License.
This code has been developed and maintained by <NAME>.

You can send comments, patches, questions [here on github](https://github.com/evilsocket/phpgibson/issues) or to <EMAIL> ([@evilsocket](http://twitter.com/evilsocket)).


# Table of contents
-----
1. [Installing/Configuring](#installingconfiguring)
   * [Installation](#installation)
   * [Installation on OSX](#installation-on-osx)
   * [Building on Windows](#building-on-windows)
1. [Classes and methods](#classes-and-methods)
   * [Usage](#usage)
   * [Connection](#connection)
   * [Methods](#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](#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)

### Class Gibson
-----
_**Description**_: Creates a Gibson client

##### *Example*

~~~
$gb = new Gibson();
~~~

## Connection

1. [connect](#connect) - Connect to a server
1. [quit](#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.
~~~

### quit
-----
_**Description**_: Disconnects from the Gibson instance.


## Methods

1. [getLastError](#getLastError) - If an error occurred, return its human readable description.
1. [set](#set) - Set the value for the given key, with an optional TTL.
1. [mset](#mset) - Set the value for keys verifying the given expression.
1. [ttl](#ttl) - Set the TTL of a key.
1. [mttl](#mttl) - Set the TTL for keys verifying the given expression.
1. [get](#get) - Get the value for a given key.
1. [mget](#mget) - Get the values for keys verifying the given expression.
1. [del](#del) - Delete the given key.
1. [mdel](#mdel) - Delete keys verifying the given expression.
1. [inc](#inc) - Increment by one the given key.
1. [minc](#minc) - Increment by one keys verifying the given expression.
1. [mdec](#mdec) - Decrement by one the given keys.
1. [dec](#dec) - Decrement by one keys verifying the given expression.
1. [lock](#lock) - Prevent the given key from being modified for a given amount of seconds.
1. [mlock](#mlock) - Prevent keys verifying the given expression from being modified for a given amount of seconds.
1. [unlock](#unlock) - Remove the lock on a given key.
1. [munlock](#munlock) - Remove the lock on keys verifying the given expression.
1. [count](#count) - Count items for a given expression.
1. [stats](#stats) - Get system stats about the Gibson instance.
1. [ping](#stats) - 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.<commit_msg>fixed typo in the readme<commit_after># PhpGibson

The phpgibson extension provides an API for communicating with the [Gibson](http://gibson-db.in/) cache server. It is released under the BSD License.
This code has been developed and maintained by <NAME>.

You can send comments, patches, questions [here on github](https://github.com/evilsocket/phpgibson/issues) or to <EMAIL> ([@evilsocket](http://twitter.com/evilsocket)).


# Table of contents
-----
1. [Installing/Configuring](#installingconfiguring)
   * [Installation](#installation)
   * [Installation on OSX](#installation-on-osx)
   * [Building on Windows](#building-on-windows)
1. [Classes and methods](#classes-and-methods)
   * [Usage](#usage)
   * [Connection](#connection)
   * [Methods](#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](#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)

### Class Gibson
-----
_**Description**_: Creates a Gibson client

##### *Example*

~~~
$gb = new Gibson();
~~~

## Connection

1. [connect](#connect) - Connect to a server
1. [quit](#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.
~~~

### quit
-----
_**Description**_: Disconnects from the Gibson instance.


## Methods

1. [getLastError](#getLastError) - If an error occurred, return its human readable description.
1. [set](#set) - Set the value for the given key, with an optional TTL.
1. [mset](#mset) - Set the value for keys verifying the given expression.
1. [ttl](#ttl) - Set the TTL of a key.
1. [mttl](#mttl) - Set the TTL for keys verifying the given expression.
1. [get](#get) - Get the value for a given key.
1. [mget](#mget) - Get the values for keys verifying the given expression.
1. [del](#del) - Delete the given key.
1. [mdel](#mdel) - Delete keys verifying the given expression.
1. [inc](#inc) - Increment by one the given key.
1. [minc](#minc) - Increment by one keys verifying the given expression.
1. [mdec](#mdec) - Decrement by one the given keys.
1. [dec](#dec) - Decrement by one keys verifying the given expression.
1. [lock](#lock) - Prevent the given key from being modified for a given amount of seconds.
1. [mlock](#mlock) - Prevent keys verifying the given expression from being modified for a given amount of seconds.
1. [unlock](#unlock) - Remove the lock on a given key.
1. [munlock](#munlock) - Remove the lock on keys verifying the given expression.
1. [count](#count) - Count items for a given expression.
1. [stats](#stats) - Get system stats about the Gibson instance.
1. [ping](#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.
{'fraction_non_alphanumeric': 0.1483216237314598, 'fraction_numerical': 0.02615144418423107, 'mean_word_length': 3.864261983863313, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1389434', 'n_tokens_mistral': 3562, 'n_tokens_neox': 3229, 'n_words': 1191}