Git Product home page Git Product logo

pecl-memcache's Introduction

This is an official repository for pecl-memcache plugin since 2019. 

This repository contains modified pecl-memcache plugin ported to PHP8,
which was originally developed for the need of hosting company in Slovakia (Websupport.sk). 

The latest release is 8.2 (released: 2023-04-30) with support for PHP 8.0+ (incl. PHP 8.2).

Please use version 4.0.5.1 (released: 2020-12-19) for PHP 7.x from branch NON_BLOCKING_IO_php7.

See: https://github.com/websupport-sk/pecl-memcache/releases
See also release on PECL: https://pecl.php.net/package/memcache

Feel free to use it and post patches. 



Original README before 2019:

memcached module for PHP
------------------------
This module requires zlib library, used for on-the-fly data (de)compression.
Also, you'll need memcached to use it =)

The memcached website is here:
    http://www.danga.com/memcached/

You will probably need libevent to install memcached:
You can download it here: http://www.monkey.org/~provos/libevent/

How to run tests:
1. sh tests/memcache.sh
2. TEST_PHP_EXECUTABLE=/usr/local/bin/php php -dextension=modules/memcache.so run-tests.php -d extension=modules/memcache.so


New API in 3.0
------------------------

 Version 3 introduces a new class "MemcachePool" which implements the new API, the 
 old class "Memcache" is still retained (but is deprecated) with the same interface 
 for backwards compatibility. Please note that you need a new memcached version to
 use the CAS, default value to increment/decrement, append and prepend, and binary 
 protocol features.

 New INI directives are available to allow control over protocol, redundancy and hash
 strategy selection. These are
 
	# The binary protocol results in less traffic and is more efficient
	# for the client and server to generate/parse

	memcache.protocol = {ascii, binary}		# default ascii

	# When enabled the client sends requests to N servers in parallel, resulting in
	# a somewhat crude reduncancy or mirroring, suitable when used as a session 
	# storage. 
	#
	# If data integrity is of greater importance a real replicating memcached 
	# backend such as "repcached" (http://sourceforge.net/projects/repcached/) is 
	# recommended

	memcache.redundancy = <int>			# default 1
	memcache.session_redundancy = <int>		# default 2

	# Hash strategy and function selection. The consistent hashing strategy
	# is now the default as it allows servers to be added and removed from
	# the pool without resulting in all or most keys being re-mapped to 
	# other server (ie. voiding the cache)

	memcache.hash_strategy = {standard, consistent}	# default consistent
	memcache.hash_function = {crc32, fnv}			# default crc32
	
	# Compression is enabled by default, the threshold which control the minimum 
	# string length which triggers compresssion can be changed as
	
	memcache.compress_threshold = <int>		# default 20000


 The directives are used by the MemcachePool constructor so you can instantiate 
 several pools with different settings by using ini_set() creativly. For example
 
	ini_set('memcache.protocol', 'binary');

	$binarypool = new MemcachePool();
	$binarypool->addServer(...)

	ini_set('memcache.protocol', 'ascii');
	ini_set('memcache.redundancy', '2');

	$redundantpool = new MemcachePool();
	$redundantpool->addServer(...)

	ini_set('memcache.redundancy', '1');
 

 The new interface looks like 

class MemcachePool() {
	bool connect(string host, int tcp_port = 11211, int udp_port = 0, bool persistent = true, int weight = 1, int timeout = 1, int retry_interval = 15)
	bool addServer(string host, int tcp_port = 11211, int udp_port = 0, bool persistent = true, int weight = 1, int timeout = 1, int retry_interval = 15, bool status = true)
	bool setServerParams(string host, int tcp_port = 11211, int timeout = 1, int retry_interval = 15, bool status = true)
	
	/**
	 * Supports fetching flags and CAS values
	 */
	mixed get(mixed key, mixed &flags = null, mixed &cas = null)
	
	/**
	 * Supports multi-set, for example
	 *  $memcache->set(array('key1' => 'val1', 'key2' => 'val1'), null, 0, 60)
	 */
	bool add(mixed key, mixed var = null, int flag = 0, int exptime = 0)
	bool set(mixed key, mixed var = null, int flag = 0, int exptime = 0)
	bool replace(mixed key, mixed var = null, int flag = 0, int exptime = 0)
	
	/**
	 * Compare-and-Swap, uses the CAS param from MemcachePool::get() 
	 */
	bool cas(mixed key, mixed var = null, int flag = 0, int exptime = 0, int cas = 0)
	
	/**
	 * Prepends/appends a value to an existing one
	 */
	bool append(mixed key, mixed var = null, int flag = 0, int exptime = 0)
	bool prepend(mixed key, mixed var = null, int flag = 0, int exptime = 0)
	
	/**
	 * Supports multi-key operations, for example
	 *  $memcache->delete(array('key1', 'key2'))
	 */
	bool delete(mixed key, int exptime = 0)

	/**
	 * Supports multi-key operations, for example
	 *  $memcache->increment(array('key1', 'key2'), 1, 0, 0)
	 *
	 * The new defval (default value) and exptime (expiration time) are used
	 * if the key doesn't already exist. They must be supplied (even if 0) for
	 * this to be enabled.
	 *
	 * Returns an integer with the new value if key is a string
	 * Returns an array of integers if the key is an array
	 */
	mixed increment(mixed key, int value = 1, int defval = 0, int exptime = 0)
	mixed decrement(mixed key, int value = 1, int defval = 0, int exptime = 0)
	
	/**
	 * Assigns a pool-specific failure callback which will be called when 
	 * a request fails. May be null in order to disable callbacks. The callback
	 * receive arguments like
	 *
	 *  function mycallback($host, $tcp_port, $udp_port, $error, $errnum)
	 *
	 * Where $host and $error are strings or null, the other params are integers.
	 */
	bool setFailureCallback(function callback)
	
	/**
	 * Locates the server a given would be hashed to
	 * 
	 * Returns a string "hostname:port" on success
	 * Returns false on failure such as invalid key
	 */
	string findServer(string key)
}


Maintainers:
Herman J. Radtke III	hradtke at php dot net

pecl-memcache's People

Contributors

tony2001 avatar tomassrnka avatar pierrejoye avatar remicollet avatar szabolcsbalogh avatar thesource93 avatar weltling avatar edinkad avatar rossaffandy avatar aidvu avatar andypost avatar fmk avatar jan-e avatar willfitch avatar zaffy avatar drealecs avatar elbandi avatar gsmaul avatar borodiychuk avatar bobvandevijver avatar dward avatar glensc avatar tyrael avatar pmurzakov avatar rlerdorf avatar shyim avatar timgates42 avatar wez avatar kolsys avatar vnsavage avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.