DEPRECATED use official github fork instead
PHP C M4 JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
tests
CREDITS
ChangeLog
LICENSE
README.md
config.m4
config.w32
php_snappy.h
snappy.c

README.md

php-snappy

DEPRECATED

Fork of http://code.google.com/p/php-snappy.

Use the official github clone at https://github.com/kjdev/php-ext-snappy to report issues or patches.

This fork is no longer maintained and will fail with PHP 7.0.

This repository is intended to provide a better documentation to simplify use of the snappy API with PHP.

You may want to use this implementation as well: https://github.com/krakjoe/snappy/. It is really similar but offers a function snappy_validate($data); which might be rather useful.

Installation

You need the snappy headers installed before compiling the extension. Most distributions should supply a libsnappy-dev and a libsnappy1.

PHP 5 is required.

git clone git://github.com/goatherd/php-snappy.git
cd php-snappy
phpize
./configure
make & make test & make install

Add extension=snappy.so to your php.ini.

On Debian/ Ubuntu and similar distributions you may want to add a /etc/php5/conf.d/snappy.ini for that purpose.

Usage

/**
 * Compress using snappy.
 *
 * @param string $data data to compress
 *
 * @return string  compressed data
 *         boolean false on error (and E_WARNING with further detail)
 */  
snappy_compress($data);

/**
 * Uncompress using snappy.
 * 
 * @param string $data compressed data
 *
 * @return string  uncompressed data
 *         boolean false on error (and E_WARNING with further detail)
 */
snappy_uncompress($data)

Note that integer data will be casted to string and boolean/ null will result in \000.

See examples\snappy.php for a demo CLI tool (do not use for production).

Description

Snappy was developed to reduce network traffic with neglectable overhead on the node. It is therefor quiet fast (to decompress) with a reasonable compression ratio. The developer states 2-4x for HTML data for example. Note that snappy is optimised for 64bit architectures and speed benchmarks are usally supplied for that.

At the time of writing no streaming service is known to use snappy on the fly.

With PHP it is possible to couple snappy with memcached services. But beware of the decompression times on serialised php data. Combined with igbinary it seems to provide acceptable performance and compression ratio.

More convention use cases involve message queues and data streams.

TODO

  • a real PECL setup would be nice.
  • link use case and bench statistics for PHP