cvs: pear /System_Shared SharedMemory.php package.xml /System_Shared/SharedMemory Apachenote.php Apc.php Common.php Eaccelerator.php File.php
Memcache.php Mmcache.php Sharedance.php Shmop.php Sqlite.php Systemv.php /System_Shared/docs README.TXT
| From: | Evgeny Stepanischev | Date: | Sat, 17 Sep 2005 09:06:20 +0000 |
| Subject: | cvs: pear /System_Shared SharedMemory.php package.xml /System_Shared/SharedMemory Apachenote.php Apc.php Common.php Eaccelerator.php File.php Memcache.php Mmcache.php Sharedance.php Shmop.php Sqlite.php Systemv.php /System_Shared/docs README.TXT |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-34826@lists.php.net to get a copy of this message | ||
bolk Sat Sep 17 05:06:20 2005 EDT
Added files:
/pear/System_Shared SharedMemory.php package.xml
/pear/System_Shared/SharedMemory Apachenote.php Apc.php Common.php
Eaccelerator.php File.php
Memcache.php Mmcache.php
Sharedance.php Shmop.php
Sqlite.php Systemv.php
/pear/System_Shared/docs README.TXT
Log:
http://cvs.php.net/co.php/pear/System_Shared/SharedMemory.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory.php +++ pear/System_Shared/SharedMemory.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: SharedMemory.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ class System_SharedMemory { /** * Create a new shared mem object * * @param string $type the shared mem type (or false on autodetect) * @param array $options an associative array of option names and values * * @return object a new System_Shared object * */ function &factory($type = false, $options = array()) { if ($type === false) { $type = System_SharedMemory::getAvailableTypes(true); } else { $type = ucfirst(strtolower($type)); } require_once 'System/SharedMemory/'.$type . '.php'; $class = 'System_SharedMemory_' . $type; $ref = &new $class($options); return $ref; } /** * Get available types or first one * * @param bool $only_first false if need all types and true if only first one * * @return mixed list of available types (array) or first one (string) * */ function getAvailableTypes($only_first = false) { $detect = array ( 'eaccelerator' => 'Eaccelerator', // Eaccelerator (Turck MMcache fork) 'mmcache' => 'Mmcache', // Turck MMCache 'Memcache' => 'Memcached', // Memched 'shmop_open' => 'Shmop', // Shmop 'apc_fetch' => 'Apc', // APC 'apache_note' => 'Apachenote', // Apache note 'shm_get_var' => 'Systemv', // System V 'sqlite_open' => 'Sqlite', // SQLite 'file' => 'File', // Plain text 'fsockopen' => 'Sharedance', // Sharedance ); $types = array(); foreach ($detect as $func=>$val) { if (function_exists($func) || class_exists($func)) { if ($only_first) { return $val; } $types[] = $val; } } return $types; } } ?> http://cvs.php.net/co.php/pear/System_Shared/package.xml?r=1.1&p=1 Index: pear/System_Shared/package.xml +++ pear/System_Shared/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>System_SharedMemory</name> <summary>common OO-style shared memory API</summary> <description>OO-style shared memory API for several shared memory engines</description> <maintainers> <maintainer> <user>bolk</user> <name>Evgeny Stepanischev</name> <email>bolk@lixil.ru</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.0.4</version> <date>2005-09-07</date> <license>PHP License</license> <state>beta</state> <notes>This is the first release.</notes> <deps> <dep type="php" rel="ge" version="4.0.0"/> </deps> <provides type="class" name="System_SharedMemory" /> <provides type="class" name="System_SharedMemory_Apachenote" /> <provides type="class" name="System_SharedMemory_Apc" /> <provides type="class" name="System_SharedMemory_Common" /> <provides type="class" name="System_SharedMemory_Eaccelerator" /> <provides type="class" name="System_SharedMemory_File" /> <provides type="class" name="System_SharedMemory_Memcache" /> <provides type="class" name="System_SharedMemory_Mmcache" /> <provides type="class" name="System_SharedMemory_Shmop" /> <provides type="class" name="System_SharedMemory_Systemv" /> <provides type="function" name="System_SharedMemory::factory" /> <provides type="function" name="System_SharedMemory::getAvailableTypes" /> <provides type="function" name="System_SharedMemory_Apachenote::get" /> <provides type="function" name="System_SharedMemory_Apachenote::set" /> <provides type="function" name="System_SharedMemory_Apachenote::rm" /> <provides type="function" name="System_SharedMemory_Apc::get" /> <provides type="function" name="System_SharedMemory_Apc::set" /> <provides type="function" name="System_SharedMemory_Apc::rm" /> <provides type="function" name="System_SharedMemory_Eaccelerator::get" /> <provides type="function" name="System_SharedMemory_Eaccelerator::set" /> <provides type="function" name="System_SharedMemory_Eaccelerator::rm" /> <provides type="function" name="System_SharedMemory_File::isConnected" /> <provides type="function" name="System_SharedMemory_File::get" /> <provides type="function" name="System_SharedMemory_File::set" /> <provides type="function" name="System_SharedMemory_File::rm" /> <provides type="class" name="System_SharedMemory_Memache" extends="System_SharedMemory_Common" /> <provides type="function" name="System_SharedMemory_Memache::System_SharedMemory_Memcache" /> <provides type="function" name="System_SharedMemory_Memache::isConnected" /> <provides type="function" name="System_SharedMemory_Memache::get" /> <provides type="function" name="System_SharedMemory_Memache::set" /> <provides type="function" name="System_SharedMemory_Memache::rm" /> <provides type="function" name="System_SharedMemory_Mmcache::get" /> <provides type="function" name="System_SharedMemory_Mmcache::set" /> <provides type="function" name="System_SharedMemory_Mmcache::rm" /> <provides type="function" name="System_SharedMemory_Shmop::get" /> <provides type="function" name="System_SharedMemory_Shmop::set" /> <provides type="function" name="System_SharedMemory_Shmop::rm" /> <provides type="function" name="System_SharedMemory_Common::isConnected" /> <provides type="function" name="System_SharedMemory_Common::engineName" /> <provides type="function" name="System_SharedMemory_Systemv::isConnected" /> <provides type="function" name="System_SharedMemory_Systemv::get" /> <provides type="function" name="System_SharedMemory_Systemv::set" /> <provides type="function" name="System_SharedMemory_Systemv::rm" /> <provides type="class" name="System_SharedMemory_Sqlite" extends="System_SharedMemory_Common" /> <provides type="function" name="System_SharedMemory_Sqlite::isConnected" /> <provides type="function" name="System_SharedMemory_Sqlite::get" /> <filelist> <file role="php" baseinstalldir="/System" md5sum="3882530a499ac33b13cb821f9d68ec63" name="SharedMemory.php"/> <file role="doc" baseinstalldir="/System" md5sum="191f3cb83b11959d6c22d32c678e01f2" name="docs/README.TXT"/> <file role="php" baseinstalldir="/System" md5sum="68b64cb5d2a5c43f467840f847416df5" name="SharedMemory/Apachenote.php"/> <file role="php" baseinstalldir="/System" md5sum="2dd1a30355fbdf599c133dfff515d775" name="SharedMemory/Apc.php"/> <file role="php" baseinstalldir="/System" md5sum="02e3830d32dfeb0dc423275a4a59512d" name="SharedMemory/Eaccelerator.php"/> <file role="php" baseinstalldir="/System" md5sum="02d96bc76d28962d49d6a7763c087b5b" name="SharedMemory/File.php"/> <file role="php" baseinstalldir="/System" md5sum="4552b39dc95b468c9b81b4341a8445d5" name="SharedMemory/Memcache.php"/> <file role="php" baseinstalldir="/System" md5sum="74b0cd967a6831243e5f35508c3091e1" name="SharedMemory/Mmcache.php"/> <file role="php" baseinstalldir="/System" md5sum="da1d707369b5c44d851e6d1828dd10d1" name="SharedMemory/Shmop.php"/> <file role="php" baseinstalldir="/System" md5sum="3a840d2c10b6bb3d94510b682199538f" name="SharedMemory/Common.php"/> <file role="php" baseinstalldir="/System" md5sum="89e3ed8567566ab694ac2d5cee7cc63a" name="SharedMemory/Systemv.php"/> <file role="php" baseinstalldir="/System" md5sum="0cb21b453b02eacb9604cc3fe9098894" name="SharedMemory/Sqlite.php"/> <file role="php" baseinstalldir="/System" name="SharedMemory/Sharedance.php"/> </filelist> </release> </package> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Apachenote.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Apachenote.php +++ pear/System_Shared/SharedMemory/Apachenote.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Apachenote.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Apachenote extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return unserialize(apache_note($name)); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success * @access public */ function set($name, $value) { apache_note($name, serialize($value)); return true; } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { apache_note($name, null); return true; } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Apc.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Apc.php +++ pear/System_Shared/SharedMemory/Apc.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Apc.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Apc extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return apc_fetch($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { return apc_store($name, $value, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { return apc_delete($name); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Common.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Common.php +++ pear/System_Shared/SharedMemory/Common.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Common.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ class System_SharedMemory_Common { /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return true; } /** * returns name of current engine * * @return string name of engine * @access public */ function engineName() { return strtolower(substr(basename(__FILE__), 0, -4)); } /** * fill non-set properties by def values * * @param array options array * @param array hash of pairs keys and default values * * @return array filled array * @access public */ function _default($options, $def) { foreach ($def as $key=>$val) { if (!isset($options[$key])) { $options[$key] = $val; } } return $options; } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Eaccelerator.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Eaccelerator.php +++ pear/System_Shared/SharedMemory/Eaccelerator.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Eaccelerator.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Eaccelerator extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return eaccelerator_get($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { eaccelerator_lock($name); return eaccelerator_put ($name, $value, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { return eaccelerator_rm($name); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/File.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/File.php +++ pear/System_Shared/SharedMemory/File.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: File.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; require_once "PEAR.php"; class System_SharedMemory_File extends System_SharedMemory_Common { /** * Contains internal options * * @var string * * @access private */ var $_options; /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_File($options) { $this->_options = $this->_default($options, array ( 'tmp' => '/tmp', )); $this->_connected = is_writeable($this->_options['tmp']) && is_dir($this->_options['tmp']); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return mixed true on success or PEAR_error on fail * @access public */ function get($name) { $name = $this->_options['tmp'].'/smf_'.md5($name); if (!file_exists($name)) { return array(); } $fp = fopen($name, 'rb'); if (is_resource($fp)) { flock ($fp, LOCK_SH); $str = fread($fp, filesize($name)); fclose($fp); return $str == '' ? array() : unserialize($str); } return PEAR::raiseError('Cannot open file.', 1); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return mixed true on success or PEAR_error on fail * @access public */ function set($name, $value) { $fp = fopen($this->_options['tmp'].'/smf_'.md5($name), 'ab'); if (is_resource($fp)) { flock ($fp, LOCK_EX); ftruncate($fp, 0); fseek($fp, 0); fwrite($fp, serialize($value)); fclose($fp); clearstatcache(); return true; } return PEAR::raiseError('Cannot write to file.', 2); } /** * remove variable from memory * * @param string $name name of the variable * * @return mixed true on success or PEAR_error on fail * @access public */ function rm($name) { $name = $this->_options['tmp'].'/smf_'.md5($name); if (file_exists($name)) { unlink($name); } } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Memcache.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Memcache.php +++ pear/System_Shared/SharedMemory/Memcache.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Memcache.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Memache extends System_SharedMemory_Common { /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * Memcache object instance * * @var object * * @access private */ var $_mc; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_Memcache($options) { extract($this->_default($options, array ( 'host' => '127.0.0.1', 'port' => 11211, 'timeout' => false, 'persistent' => false, ))); $func = $persistent ? 'pconnect' : 'connect'; $this->_mc = &new Memcache; $this->_connected = $timeout === false ? $this->_mc->$func($host, $port) : $this->_mc->$func($host, $port, $timeout); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return $this->_mc->get($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { return $this->_mc->set($name, $value, 0, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name, $ttl = false) { return $ttl === false ? $this->_mc->delete($name) : $this->_mc->delete($name, $ttl); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Mmcache.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Mmcache.php +++ pear/System_Shared/SharedMemory/Mmcache.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Mmcache.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Mmcache extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return mmcache_get($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { mmcache_lock($name); return mmcache_put ($name, $value, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { return mmcache_rm($name); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Sharedance.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Sharedance.php +++ pear/System_Shared/SharedMemory/Sharedance.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Sharedance.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Sharedance extends System_SharedMemory_Common { /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * connection handler * * @var string * * @access private */ var $_h; /** * Constructor. Init all variables. * * @param array $options * * @access public */ /** * Contains internal options * * @var string * * @access private */ var $_options; function System_SharedMemory_Sharedance($options) { $this->_options = ($this->_default($options, array ( 'host' => '127.0.0.1', 'port' => 1042, 'timeout' => 10, ))); $this->_h = null; $this->_open(); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { $this->_open(); $s = 'F' . pack('N', strlen($name)) . $name; fwrite($this->_h, $s); for ($data = ''; !feof($this->_h);) { $data .= fread($this->_h, 4096); } $this->_close(); return $data === '' ? null : unserialize($data); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value) { $this->_open(); $value = serialize($value); $s = 'S' . pack('NN', strlen($name), strlen($value)) . $name . $value; fwrite($this->_h, $s); $ret = fgets($this->_h); $this->_close(); return $ret === "OK\n"; } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { $this->_open(); $s = 'D' . pack('N', strlen($name)) . $name; fwrite($this->_h, $s); $ret = fgets($this->_h); $this->_close(); return $ret === "OK\n"; } /** * close connection to backend * (sharedance isn't support persistent connection) * * @access private */ function _close() { fclose($this->_h); $this->_h = false; } /** * open connection to backend if it doesn't connected yet * * @access private */ function _open() { if (!is_resource($this->_h)) { $this->_h = fsockopen($this->_options['host'], $this->_options['port'], $_, $_, $this->_options['timeout']); $this->_connected = is_resource($this->_h); } } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Shmop.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Shmop.php +++ pear/System_Shared/SharedMemory/Shmop.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Shmop.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; require_once "PEAR.php"; class System_SharedMemory_Shmop extends System_SharedMemory_Common { /** * handler for shmop_* functions * * @var string * * @access private */ var $_h; /** * Contains internal options * * @var string * * @access private */ var $_options; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_Shmop($options) { $this->_options = $this->_default($options, array ( 'size' => 1048576, 'tmp' => '/tmp', 'project' => 's' )); $this->_h = $this->_ftok($this->_options['project']); } /** * returns value of variable in shared mem * * @param mixed $name name of variable or false if all variables needs * * @return mixed PEAR_error or value of the variable * @access public */ function get($name = false) { $id = shmop_open($this->_h, 'c', 0600, $this->_options['size']); if ($id !== false) { $ret = unserialize(shmop_read($id, 0, shmop_size($id))); shmop_close($id); if ($name === false) { return $ret; } return isset($ret[$name]) ? $ret[$name] : null; } return PEAR::raiseError('Cannot open shmop.', 1); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success * @access public */ function set($name, $value) { $lh = $this->_lock(); $val = $this->get(); if (!is_array($val)) { $val = array(); } $val[$name] = $value; $val = serialize($val); return $this->_write($val, $lh); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { $lh = $this->_lock(); $val = $this->get(); if (!is_array($val)) { $val = array(); } unset($val[$name]); $val = serialize($val); return $this->_write($val, $lh); } /** * ftok emulation for Windows * * @param string $project project ID * * @access private */ function _ftok($project) { if (function_exists('ftok')) { return ftok(__FILE__, $project); } $s = stat(__FILE__); return sprintf("%u", (($s['ino'] & 0xffff) | (($s['dev'] & 0xff) << 16) | (($project & 0xff) << 24))); } /** * write to the shared memory * * @param string $val values of all variables * @param resource $lh lock handler * * @return mixed PEAR_error or true on success * @access private */ function _write(&$val, &$lh) { $id = shmop_open($this->_h, 'c', 0600, $this->_options['size']); if ($id) { $ret = shmop_write($id, $val, 0) == strlen($val); shmop_close($id); $this->_unlock($lh); return $ret; } $this->_unlock($lh); return PEAR::raiseError('Cannot write to shmop.', 2); } /** * access locking function * * @return resource lock handler * @access private */ function &_lock() { if (function_exists('sem_get')) { $fp = PHP_VERSION < 4.3 ? sem_get($this->_h, 1, 0600) : sem_get($this->_h, 1, 0600, 1); sem_acquire ($fp); } else { $fp = fopen($this->_options['tmp'].'/sm_'.md5($this->_h), 'w'); flock($fp, LOCK_EX); } return $fp; } /** * access unlocking function * * @param resource $fp lock handler * * @access private */ function _unlock(&$fp) { if (function_exists('sem_get')) { sem_release($fp); } else { fclose($fp); } } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Sqlite.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Sqlite.php +++ pear/System_Shared/SharedMemory/Sqlite.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Sqlite.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Sqlite extends System_SharedMemory_Common { /** * SQLite object handler * * @var object * * @access private */ var $_h; /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * hash of SQLite table options * * @var array * * @access private */ var $_options; /** * Constructor. Init all variables. * SQLite table must be created: * CREATE sharedmemory(var text PRIMARY KEY, value TEXT) * It's very important! * * @param array $options * * @access public */ function System_SharedMemory_Sqlite($options) { $this->_options = $this->_default($options, array ( 'db' => ':memory:', 'table' => 'sharedmemory', 'var' => 'var', 'value' => 'value', 'persistent' => false, )); $func = $this->_options['persistent'] ? 'sqlite_popen' : 'sqlite_open'; $this->_h = $func($this->_options['db']); $this->_connected = is_resource($this->_h); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { $name = sqlite_escape_string($name); $sql = "SELECT {$this->_options['value']} FROM {$this->_options['table']} WHERE {$this->_options['var']}='$name' LIMIT 1"; $result = sqlite_query($this->_h, $sql); if (sqlite_num_rows($result)) { return unserialize(sqlite_fetch_single($result)); } return null; } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success * @access public */ function set($name, $value) { $name = sqlite_escape_string($name); $value = sqlite_escape_string(serialize($value)); $sql = "REPLACE INTO {$this->_options['table']} ({$this->_options['var']}, {$this->_options['value']}) VALUES ('$name', '$value')"; sqlite_query($this->_h, $sql); return true; } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { $name = sqlite_escape_string($name); $sql = "DELETE FROM {$this->_options['table']} WHERE {$this->_options['var']}='$name'"; sqlite_query($this->_h, $sql); return true; } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Systemv.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Systemv.php +++ pear/System_Shared/SharedMemory/Systemv.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Systemv.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; require_once "PEAR.php"; class System_SharedMemory_Systemv extends System_SharedMemory_Common { /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * handler for shmop_* functions * * @var string * * @access private */ var $_h; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_Systemv($options) { extract($this->_default($options, array ( 'size' => false, 'project' => 's', ))); if ($size === false) { $this->_h = shm_attach($this->_ftok($project)); } else { if ($size < SHMMIN || $size > SHMMAX) { return $this->_connection = false; } $this->_h = shm_attach($this->_ftok($project), $size); } $this->_connection = true; } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param int $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return shm_get_var($this->_h, $this->_s2i($name)); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success, false on fail * @access public */ function set($name, $value) { return shm_put_var($this->_h, $this->_s2i($name), $value); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success, false on fail * @access public */ function rm($name) { return shm_remove_var($this->_h, $this->_s2i($name)); } /** * ftok emulation for Windows * * @param string $project project ID * * @access private */ function _ftok($project) { if (function_exists('ftok')) { return ftok(__FILE__, $project); } $s = stat(__FILE__); return sprintf("%u", (($s['ino'] & 0xffff) | (($s['dev'] & 0xff) << 16) | (($project & 0xff) << 24))); } /** * convert string to int * * @param string $name string to conversion * * @access private */ function _s2i($name) { return unpack('N', str_pad($name, 4, "\0", STR_PAD_LEFT)); } } ?> http://cvs.php.net/co.php/pear/System_Shared/docs/README.TXT?r=1.1&p=1 Index: pear/System_Shared/docs/README.TXT +++ pear/System_Shared/docs/README.TXT Project home page (Russian): http://bolk.exler.ru/files/shared/ Usage: include_once 'System/SharedMemory.php'; $Shared =& System_SharedMemory::factory(); $Shared->set('name', 'something'); echo $Shared->get('name'); $Shared->rm('name');
http://cvs.php.net/co.php/pear/System_Shared/SharedMemory.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory.php +++ pear/System_Shared/SharedMemory.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: SharedMemory.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ class System_SharedMemory { /** * Create a new shared mem object * * @param string $type the shared mem type (or false on autodetect) * @param array $options an associative array of option names and values * * @return object a new System_Shared object * */ function &factory($type = false, $options = array()) { if ($type === false) { $type = System_SharedMemory::getAvailableTypes(true); } else { $type = ucfirst(strtolower($type)); } require_once 'System/SharedMemory/'.$type . '.php'; $class = 'System_SharedMemory_' . $type; $ref = &new $class($options); return $ref; } /** * Get available types or first one * * @param bool $only_first false if need all types and true if only first one * * @return mixed list of available types (array) or first one (string) * */ function getAvailableTypes($only_first = false) { $detect = array ( 'eaccelerator' => 'Eaccelerator', // Eaccelerator (Turck MMcache fork) 'mmcache' => 'Mmcache', // Turck MMCache 'Memcache' => 'Memcached', // Memched 'shmop_open' => 'Shmop', // Shmop 'apc_fetch' => 'Apc', // APC 'apache_note' => 'Apachenote', // Apache note 'shm_get_var' => 'Systemv', // System V 'sqlite_open' => 'Sqlite', // SQLite 'file' => 'File', // Plain text 'fsockopen' => 'Sharedance', // Sharedance ); $types = array(); foreach ($detect as $func=>$val) { if (function_exists($func) || class_exists($func)) { if ($only_first) { return $val; } $types[] = $val; } } return $types; } } ?> http://cvs.php.net/co.php/pear/System_Shared/package.xml?r=1.1&p=1 Index: pear/System_Shared/package.xml +++ pear/System_Shared/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>System_SharedMemory</name> <summary>common OO-style shared memory API</summary> <description>OO-style shared memory API for several shared memory engines</description> <maintainers> <maintainer> <user>bolk</user> <name>Evgeny Stepanischev</name> <email>bolk@lixil.ru</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.0.4</version> <date>2005-09-07</date> <license>PHP License</license> <state>beta</state> <notes>This is the first release.</notes> <deps> <dep type="php" rel="ge" version="4.0.0"/> </deps> <provides type="class" name="System_SharedMemory" /> <provides type="class" name="System_SharedMemory_Apachenote" /> <provides type="class" name="System_SharedMemory_Apc" /> <provides type="class" name="System_SharedMemory_Common" /> <provides type="class" name="System_SharedMemory_Eaccelerator" /> <provides type="class" name="System_SharedMemory_File" /> <provides type="class" name="System_SharedMemory_Memcache" /> <provides type="class" name="System_SharedMemory_Mmcache" /> <provides type="class" name="System_SharedMemory_Shmop" /> <provides type="class" name="System_SharedMemory_Systemv" /> <provides type="function" name="System_SharedMemory::factory" /> <provides type="function" name="System_SharedMemory::getAvailableTypes" /> <provides type="function" name="System_SharedMemory_Apachenote::get" /> <provides type="function" name="System_SharedMemory_Apachenote::set" /> <provides type="function" name="System_SharedMemory_Apachenote::rm" /> <provides type="function" name="System_SharedMemory_Apc::get" /> <provides type="function" name="System_SharedMemory_Apc::set" /> <provides type="function" name="System_SharedMemory_Apc::rm" /> <provides type="function" name="System_SharedMemory_Eaccelerator::get" /> <provides type="function" name="System_SharedMemory_Eaccelerator::set" /> <provides type="function" name="System_SharedMemory_Eaccelerator::rm" /> <provides type="function" name="System_SharedMemory_File::isConnected" /> <provides type="function" name="System_SharedMemory_File::get" /> <provides type="function" name="System_SharedMemory_File::set" /> <provides type="function" name="System_SharedMemory_File::rm" /> <provides type="class" name="System_SharedMemory_Memache" extends="System_SharedMemory_Common" /> <provides type="function" name="System_SharedMemory_Memache::System_SharedMemory_Memcache" /> <provides type="function" name="System_SharedMemory_Memache::isConnected" /> <provides type="function" name="System_SharedMemory_Memache::get" /> <provides type="function" name="System_SharedMemory_Memache::set" /> <provides type="function" name="System_SharedMemory_Memache::rm" /> <provides type="function" name="System_SharedMemory_Mmcache::get" /> <provides type="function" name="System_SharedMemory_Mmcache::set" /> <provides type="function" name="System_SharedMemory_Mmcache::rm" /> <provides type="function" name="System_SharedMemory_Shmop::get" /> <provides type="function" name="System_SharedMemory_Shmop::set" /> <provides type="function" name="System_SharedMemory_Shmop::rm" /> <provides type="function" name="System_SharedMemory_Common::isConnected" /> <provides type="function" name="System_SharedMemory_Common::engineName" /> <provides type="function" name="System_SharedMemory_Systemv::isConnected" /> <provides type="function" name="System_SharedMemory_Systemv::get" /> <provides type="function" name="System_SharedMemory_Systemv::set" /> <provides type="function" name="System_SharedMemory_Systemv::rm" /> <provides type="class" name="System_SharedMemory_Sqlite" extends="System_SharedMemory_Common" /> <provides type="function" name="System_SharedMemory_Sqlite::isConnected" /> <provides type="function" name="System_SharedMemory_Sqlite::get" /> <filelist> <file role="php" baseinstalldir="/System" md5sum="3882530a499ac33b13cb821f9d68ec63" name="SharedMemory.php"/> <file role="doc" baseinstalldir="/System" md5sum="191f3cb83b11959d6c22d32c678e01f2" name="docs/README.TXT"/> <file role="php" baseinstalldir="/System" md5sum="68b64cb5d2a5c43f467840f847416df5" name="SharedMemory/Apachenote.php"/> <file role="php" baseinstalldir="/System" md5sum="2dd1a30355fbdf599c133dfff515d775" name="SharedMemory/Apc.php"/> <file role="php" baseinstalldir="/System" md5sum="02e3830d32dfeb0dc423275a4a59512d" name="SharedMemory/Eaccelerator.php"/> <file role="php" baseinstalldir="/System" md5sum="02d96bc76d28962d49d6a7763c087b5b" name="SharedMemory/File.php"/> <file role="php" baseinstalldir="/System" md5sum="4552b39dc95b468c9b81b4341a8445d5" name="SharedMemory/Memcache.php"/> <file role="php" baseinstalldir="/System" md5sum="74b0cd967a6831243e5f35508c3091e1" name="SharedMemory/Mmcache.php"/> <file role="php" baseinstalldir="/System" md5sum="da1d707369b5c44d851e6d1828dd10d1" name="SharedMemory/Shmop.php"/> <file role="php" baseinstalldir="/System" md5sum="3a840d2c10b6bb3d94510b682199538f" name="SharedMemory/Common.php"/> <file role="php" baseinstalldir="/System" md5sum="89e3ed8567566ab694ac2d5cee7cc63a" name="SharedMemory/Systemv.php"/> <file role="php" baseinstalldir="/System" md5sum="0cb21b453b02eacb9604cc3fe9098894" name="SharedMemory/Sqlite.php"/> <file role="php" baseinstalldir="/System" name="SharedMemory/Sharedance.php"/> </filelist> </release> </package> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Apachenote.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Apachenote.php +++ pear/System_Shared/SharedMemory/Apachenote.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Apachenote.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Apachenote extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return unserialize(apache_note($name)); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success * @access public */ function set($name, $value) { apache_note($name, serialize($value)); return true; } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { apache_note($name, null); return true; } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Apc.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Apc.php +++ pear/System_Shared/SharedMemory/Apc.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Apc.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Apc extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return apc_fetch($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { return apc_store($name, $value, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { return apc_delete($name); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Common.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Common.php +++ pear/System_Shared/SharedMemory/Common.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Common.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ class System_SharedMemory_Common { /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return true; } /** * returns name of current engine * * @return string name of engine * @access public */ function engineName() { return strtolower(substr(basename(__FILE__), 0, -4)); } /** * fill non-set properties by def values * * @param array options array * @param array hash of pairs keys and default values * * @return array filled array * @access public */ function _default($options, $def) { foreach ($def as $key=>$val) { if (!isset($options[$key])) { $options[$key] = $val; } } return $options; } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Eaccelerator.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Eaccelerator.php +++ pear/System_Shared/SharedMemory/Eaccelerator.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Eaccelerator.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Eaccelerator extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return eaccelerator_get($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { eaccelerator_lock($name); return eaccelerator_put ($name, $value, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { return eaccelerator_rm($name); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/File.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/File.php +++ pear/System_Shared/SharedMemory/File.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: File.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; require_once "PEAR.php"; class System_SharedMemory_File extends System_SharedMemory_Common { /** * Contains internal options * * @var string * * @access private */ var $_options; /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_File($options) { $this->_options = $this->_default($options, array ( 'tmp' => '/tmp', )); $this->_connected = is_writeable($this->_options['tmp']) && is_dir($this->_options['tmp']); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return mixed true on success or PEAR_error on fail * @access public */ function get($name) { $name = $this->_options['tmp'].'/smf_'.md5($name); if (!file_exists($name)) { return array(); } $fp = fopen($name, 'rb'); if (is_resource($fp)) { flock ($fp, LOCK_SH); $str = fread($fp, filesize($name)); fclose($fp); return $str == '' ? array() : unserialize($str); } return PEAR::raiseError('Cannot open file.', 1); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return mixed true on success or PEAR_error on fail * @access public */ function set($name, $value) { $fp = fopen($this->_options['tmp'].'/smf_'.md5($name), 'ab'); if (is_resource($fp)) { flock ($fp, LOCK_EX); ftruncate($fp, 0); fseek($fp, 0); fwrite($fp, serialize($value)); fclose($fp); clearstatcache(); return true; } return PEAR::raiseError('Cannot write to file.', 2); } /** * remove variable from memory * * @param string $name name of the variable * * @return mixed true on success or PEAR_error on fail * @access public */ function rm($name) { $name = $this->_options['tmp'].'/smf_'.md5($name); if (file_exists($name)) { unlink($name); } } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Memcache.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Memcache.php +++ pear/System_Shared/SharedMemory/Memcache.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Memcache.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Memache extends System_SharedMemory_Common { /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * Memcache object instance * * @var object * * @access private */ var $_mc; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_Memcache($options) { extract($this->_default($options, array ( 'host' => '127.0.0.1', 'port' => 11211, 'timeout' => false, 'persistent' => false, ))); $func = $persistent ? 'pconnect' : 'connect'; $this->_mc = &new Memcache; $this->_connected = $timeout === false ? $this->_mc->$func($host, $port) : $this->_mc->$func($host, $port, $timeout); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return $this->_mc->get($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { return $this->_mc->set($name, $value, 0, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name, $ttl = false) { return $ttl === false ? $this->_mc->delete($name) : $this->_mc->delete($name, $ttl); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Mmcache.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Mmcache.php +++ pear/System_Shared/SharedMemory/Mmcache.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Mmcache.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Mmcache extends System_SharedMemory_Common { /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return mmcache_get($name); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value, $ttl = 0) { mmcache_lock($name); return mmcache_put ($name, $value, $ttl); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { return mmcache_rm($name); } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Sharedance.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Sharedance.php +++ pear/System_Shared/SharedMemory/Sharedance.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Sharedance.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Sharedance extends System_SharedMemory_Common { /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * connection handler * * @var string * * @access private */ var $_h; /** * Constructor. Init all variables. * * @param array $options * * @access public */ /** * Contains internal options * * @var string * * @access private */ var $_options; function System_SharedMemory_Sharedance($options) { $this->_options = ($this->_default($options, array ( 'host' => '127.0.0.1', 'port' => 1042, 'timeout' => 10, ))); $this->_h = null; $this->_open(); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { $this->_open(); $s = 'F' . pack('N', strlen($name)) . $name; fwrite($this->_h, $s); for ($data = ''; !feof($this->_h);) { $data .= fread($this->_h, 4096); } $this->_close(); return $data === '' ? null : unserialize($data); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * @param int $ttl (optional) time to life of the variable * * @return bool true on success * @access public */ function set($name, $value) { $this->_open(); $value = serialize($value); $s = 'S' . pack('NN', strlen($name), strlen($value)) . $name . $value; fwrite($this->_h, $s); $ret = fgets($this->_h); $this->_close(); return $ret === "OK\n"; } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { $this->_open(); $s = 'D' . pack('N', strlen($name)) . $name; fwrite($this->_h, $s); $ret = fgets($this->_h); $this->_close(); return $ret === "OK\n"; } /** * close connection to backend * (sharedance isn't support persistent connection) * * @access private */ function _close() { fclose($this->_h); $this->_h = false; } /** * open connection to backend if it doesn't connected yet * * @access private */ function _open() { if (!is_resource($this->_h)) { $this->_h = fsockopen($this->_options['host'], $this->_options['port'], $_, $_, $this->_options['timeout']); $this->_connected = is_resource($this->_h); } } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Shmop.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Shmop.php +++ pear/System_Shared/SharedMemory/Shmop.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Shmop.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; require_once "PEAR.php"; class System_SharedMemory_Shmop extends System_SharedMemory_Common { /** * handler for shmop_* functions * * @var string * * @access private */ var $_h; /** * Contains internal options * * @var string * * @access private */ var $_options; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_Shmop($options) { $this->_options = $this->_default($options, array ( 'size' => 1048576, 'tmp' => '/tmp', 'project' => 's' )); $this->_h = $this->_ftok($this->_options['project']); } /** * returns value of variable in shared mem * * @param mixed $name name of variable or false if all variables needs * * @return mixed PEAR_error or value of the variable * @access public */ function get($name = false) { $id = shmop_open($this->_h, 'c', 0600, $this->_options['size']); if ($id !== false) { $ret = unserialize(shmop_read($id, 0, shmop_size($id))); shmop_close($id); if ($name === false) { return $ret; } return isset($ret[$name]) ? $ret[$name] : null; } return PEAR::raiseError('Cannot open shmop.', 1); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success * @access public */ function set($name, $value) { $lh = $this->_lock(); $val = $this->get(); if (!is_array($val)) { $val = array(); } $val[$name] = $value; $val = serialize($val); return $this->_write($val, $lh); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { $lh = $this->_lock(); $val = $this->get(); if (!is_array($val)) { $val = array(); } unset($val[$name]); $val = serialize($val); return $this->_write($val, $lh); } /** * ftok emulation for Windows * * @param string $project project ID * * @access private */ function _ftok($project) { if (function_exists('ftok')) { return ftok(__FILE__, $project); } $s = stat(__FILE__); return sprintf("%u", (($s['ino'] & 0xffff) | (($s['dev'] & 0xff) << 16) | (($project & 0xff) << 24))); } /** * write to the shared memory * * @param string $val values of all variables * @param resource $lh lock handler * * @return mixed PEAR_error or true on success * @access private */ function _write(&$val, &$lh) { $id = shmop_open($this->_h, 'c', 0600, $this->_options['size']); if ($id) { $ret = shmop_write($id, $val, 0) == strlen($val); shmop_close($id); $this->_unlock($lh); return $ret; } $this->_unlock($lh); return PEAR::raiseError('Cannot write to shmop.', 2); } /** * access locking function * * @return resource lock handler * @access private */ function &_lock() { if (function_exists('sem_get')) { $fp = PHP_VERSION < 4.3 ? sem_get($this->_h, 1, 0600) : sem_get($this->_h, 1, 0600, 1); sem_acquire ($fp); } else { $fp = fopen($this->_options['tmp'].'/sm_'.md5($this->_h), 'w'); flock($fp, LOCK_EX); } return $fp; } /** * access unlocking function * * @param resource $fp lock handler * * @access private */ function _unlock(&$fp) { if (function_exists('sem_get')) { sem_release($fp); } else { fclose($fp); } } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Sqlite.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Sqlite.php +++ pear/System_Shared/SharedMemory/Sqlite.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Sqlite.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; class System_SharedMemory_Sqlite extends System_SharedMemory_Common { /** * SQLite object handler * * @var object * * @access private */ var $_h; /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * hash of SQLite table options * * @var array * * @access private */ var $_options; /** * Constructor. Init all variables. * SQLite table must be created: * CREATE sharedmemory(var text PRIMARY KEY, value TEXT) * It's very important! * * @param array $options * * @access public */ function System_SharedMemory_Sqlite($options) { $this->_options = $this->_default($options, array ( 'db' => ':memory:', 'table' => 'sharedmemory', 'var' => 'var', 'value' => 'value', 'persistent' => false, )); $func = $this->_options['persistent'] ? 'sqlite_popen' : 'sqlite_open'; $this->_h = $func($this->_options['db']); $this->_connected = is_resource($this->_h); } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { $name = sqlite_escape_string($name); $sql = "SELECT {$this->_options['value']} FROM {$this->_options['table']} WHERE {$this->_options['var']}='$name' LIMIT 1"; $result = sqlite_query($this->_h, $sql); if (sqlite_num_rows($result)) { return unserialize(sqlite_fetch_single($result)); } return null; } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success * @access public */ function set($name, $value) { $name = sqlite_escape_string($name); $value = sqlite_escape_string(serialize($value)); $sql = "REPLACE INTO {$this->_options['table']} ({$this->_options['var']}, {$this->_options['value']}) VALUES ('$name', '$value')"; sqlite_query($this->_h, $sql); return true; } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success * @access public */ function rm($name) { $name = sqlite_escape_string($name); $sql = "DELETE FROM {$this->_options['table']} WHERE {$this->_options['var']}='$name'"; sqlite_query($this->_h, $sql); return true; } } ?> http://cvs.php.net/co.php/pear/System_Shared/SharedMemory/Systemv.php?r=1.1&p=1 Index: pear/System_Shared/SharedMemory/Systemv.php +++ pear/System_Shared/SharedMemory/Systemv.php <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Evgeny Stepanischev <bolk@lixil.ru> | // +----------------------------------------------------------------------+ // Project home page (Russian): http://bolk.exler.ru/files/shared/ // // $Id: Systemv.php,v 1.1 2005/09/17 09:06:19 bolk Exp $ require_once 'System/SharedMemory/Common.php'; require_once "PEAR.php"; class System_SharedMemory_Systemv extends System_SharedMemory_Common { /** * true if plugin was connected to backend * * @var bool * * @access private */ var $_connected; /** * handler for shmop_* functions * * @var string * * @access private */ var $_h; /** * Constructor. Init all variables. * * @param array $options * * @access public */ function System_SharedMemory_Systemv($options) { extract($this->_default($options, array ( 'size' => false, 'project' => 's', ))); if ($size === false) { $this->_h = shm_attach($this->_ftok($project)); } else { if ($size < SHMMIN || $size > SHMMAX) { return $this->_connection = false; } $this->_h = shm_attach($this->_ftok($project), $size); } $this->_connection = true; } /** * returns true if plugin was * successfully connected to backend * * @return bool true if connected * @access public */ function isConnected() { return $this->_connected; } /** * returns value of variable in shared mem * * @param int $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { return shm_get_var($this->_h, $this->_s2i($name)); } /** * returns value of variable in shared mem * * @param string $name name of the variable * @param string $value value of the variable * * @return bool true on success, false on fail * @access public */ function set($name, $value) { return shm_put_var($this->_h, $this->_s2i($name), $value); } /** * remove variable from memory * * @param string $name name of the variable * * @return bool true on success, false on fail * @access public */ function rm($name) { return shm_remove_var($this->_h, $this->_s2i($name)); } /** * ftok emulation for Windows * * @param string $project project ID * * @access private */ function _ftok($project) { if (function_exists('ftok')) { return ftok(__FILE__, $project); } $s = stat(__FILE__); return sprintf("%u", (($s['ino'] & 0xffff) | (($s['dev'] & 0xff) << 16) | (($project & 0xff) << 24))); } /** * convert string to int * * @param string $name string to conversion * * @access private */ function _s2i($name) { return unpack('N', str_pad($name, 4, "\0", STR_PAD_LEFT)); } } ?> http://cvs.php.net/co.php/pear/System_Shared/docs/README.TXT?r=1.1&p=1 Index: pear/System_Shared/docs/README.TXT +++ pear/System_Shared/docs/README.TXT Project home page (Russian): http://bolk.exler.ru/files/shared/ Usage: include_once 'System/SharedMemory.php'; $Shared =& System_SharedMemory::factory(); $Shared->set('name', 'something'); echo $Shared->get('name'); $Shared->rm('name');