diff options
| author | Nathan Kinkade <nath@nkinka.de> | 2008-03-16 20:42:30 +0000 |
|---|---|---|
| committer | Nathan Kinkade <nath@nkinka.de> | 2008-03-16 20:42:30 +0000 |
| commit | 6d0fbeb0a7fde0cc8bae6c9944ea6b017d96968a (patch) | |
| tree | 7da954e7aaa5c7a78bd0c0cc6911f718670ea37a /lib/adodb/adodb-memcache.lib.inc.php | |
| parent | 32482b90446a7974e4aa1a392a79f1c8e18ed200 (diff) | |
Moved some external packages into lib to make system more self contained
Diffstat (limited to 'lib/adodb/adodb-memcache.lib.inc.php')
| -rw-r--r-- | lib/adodb/adodb-memcache.lib.inc.php | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/lib/adodb/adodb-memcache.lib.inc.php b/lib/adodb/adodb-memcache.lib.inc.php new file mode 100644 index 0000000..bc6b420 --- /dev/null +++ b/lib/adodb/adodb-memcache.lib.inc.php @@ -0,0 +1,118 @@ +<?php
+
+// security - hide paths
+if (!defined('ADODB_DIR')) die();
+
+global $ADODB_INCLUDED_MEMCACHE;
+$ADODB_INCLUDED_MEMCACHE = 1;
+
+/*
+
+ V4.90 8 June 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ Released under both BSD license and Lesser GPL library license.
+ Whenever there is any discrepancy between the two licenses,
+ the BSD license will take precedence. See License.txt.
+ Set tabs to 4 for best viewing.
+
+ Latest version is available at http://adodb.sourceforge.net
+
+*/
+
+ function &getmemcache($key,&$err, $timeout=0, $host, $port)
+ {
+ $false = false;
+ $err = false;
+
+ if (!function_exists('memcache_pconnect')) {
+ $err = 'Memcache module PECL extension not found!';
+ return $false;
+ }
+
+ $memcache = new Memcache;
+ if (!@$memcache->pconnect($host, $port)) {
+ $err = 'Can\'t connect to memcache server on: '.$host.':'.$port;
+ return $false;
+ }
+
+ $rs = $memcache->get($key);
+ if (!$rs) {
+ $err = 'Item with such key doesn\'t exists on the memcached server.';
+ return $false;
+ }
+
+ $tdiff = intval($rs->timeCreated+$timeout - time());
+ if ($tdiff <= 2) {
+ switch($tdiff) {
+ case 2:
+ if ((rand() & 15) == 0) {
+ $err = "Timeout 2";
+ return $false;
+ }
+ break;
+ case 1:
+ if ((rand() & 3) == 0) {
+ $err = "Timeout 1";
+ return $false;
+ }
+ break;
+ default:
+ $err = "Timeout 0";
+ return $false;
+ }
+ }
+ return $rs;
+ }
+
+ function putmemcache($key, $rs, $host, $port, $compress, $debug=false)
+ {
+ $false = false;
+ $true = true;
+
+ if (!function_exists('memcache_pconnect')) {
+ if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
+ return $false;
+ }
+
+ $memcache = new Memcache;
+ if (!@$memcache->pconnect($host, $port)) {
+ if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
+ return $false;
+ }
+
+ $rs->timeCreated = time();
+ if (!$memcache->set($key, $rs, $compress, 0)) {
+ if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");
+ return $false;
+ }
+ return $true;
+ }
+
+ function flushmemcache($key=false, $host, $port, $debug=false)
+ {
+ if (!function_exists('memcache_pconnect')) {
+ if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
+ return;
+ }
+
+ $memcache = new Memcache;
+ if (!@$memcache->pconnect($host, $port)) {
+ if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
+ return;
+ }
+
+ if ($key) {
+ if (!$memcache->delete($key)) {
+ if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");
+ } else {
+ if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");
+ }
+ } else {
+ if (!$memcache->flush()) {
+ if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
+ } else {
+ if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
+ }
+ }
+ return;
+ }
+?>
|
