| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
if (!defined('ADODB_DIR')) die(); |
|---|
| 5 |
|
|---|
| 6 |
global $ADODB_INCLUDED_MEMCACHE; |
|---|
| 7 |
$ADODB_INCLUDED_MEMCACHE = 1; |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
function &getmemcache($key,&$err, $timeout=0, $host, $port) |
|---|
| 22 |
|
|---|
| 23 |
$false = false; |
|---|
| 24 |
$err = false; |
|---|
| 25 |
|
|---|
| 26 |
function_exists('memcache_pconnect')) { |
|---|
| 27 |
$err = 'Memcache module PECL extension not found!'; |
|---|
| 28 |
$false; |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
$memcache = new Memcache; |
|---|
| 32 |
$memcache->pconnect($host, $port)) { |
|---|
| 33 |
$err = 'Can\'t connect to memcache server on: '.$host.':'.$port; |
|---|
| 34 |
$false; |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
$rs = $memcache->get($key); |
|---|
| 38 |
$rs) { |
|---|
| 39 |
$err = 'Item with such key doesn\'t exists on the memcached server.'; |
|---|
| 40 |
$false; |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
$tdiff = intval($rs->timeCreated+$timeout - time()); |
|---|
| 44 |
$tdiff <= 2) { |
|---|
| 45 |
$tdiff) { |
|---|
| 46 |
2: |
|---|
| 47 |
rand() & 15) == 0) { |
|---|
| 48 |
$err = "Timeout 2"; |
|---|
| 49 |
$false; |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
1: |
|---|
| 53 |
rand() & 3) == 0) { |
|---|
| 54 |
$err = "Timeout 1"; |
|---|
| 55 |
$false; |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
$err = "Timeout 0"; |
|---|
| 60 |
$false; |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
$rs; |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
putmemcache($key, $rs, $host, $port, $compress, $debug=false) |
|---|
| 67 |
|
|---|
| 68 |
$false = false; |
|---|
| 69 |
$true = true; |
|---|
| 70 |
|
|---|
| 71 |
function_exists('memcache_pconnect')) { |
|---|
| 72 |
$debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n"); |
|---|
| 73 |
$false; |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
$memcache = new Memcache; |
|---|
| 77 |
$memcache->pconnect($host, $port)) { |
|---|
| 78 |
$debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n"); |
|---|
| 79 |
$false; |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
$rs->timeCreated = time(); |
|---|
| 83 |
$memcache->set($key, $rs, $compress, 0)) { |
|---|
| 84 |
$debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n"); |
|---|
| 85 |
$false; |
|---|
| 86 |
|
|---|
| 87 |
$true; |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
flushmemcache($key=false, $host, $port, $debug=false) |
|---|
| 91 |
|
|---|
| 92 |
function_exists('memcache_pconnect')) { |
|---|
| 93 |
$debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n"); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
$memcache = new Memcache; |
|---|
| 98 |
$memcache->pconnect($host, $port)) { |
|---|
| 99 |
$debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n"); |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
$key) { |
|---|
| 104 |
$memcache->delete($key)) { |
|---|
| 105 |
$debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n"); |
|---|
| 106 |
|
|---|
| 107 |
$debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n"); |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
$memcache->flush()) { |
|---|
| 111 |
$debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n"); |
|---|
| 112 |
|
|---|
| 113 |
$debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n"); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
?> |
|---|
| 119 |
|
|---|