Server IP : 103.119.228.120 / Your IP : 3.145.68.167 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/share/awl/inc/ |
Upload File : |
<?php /** * A simple Memcached wrapper supporting namespacing of stored values. * * @author Andrew McMillan * @license LGPL v2 or later */ class AwlCache { private static $m; private static $servers; private static $working; /** * Initialise the cache connection. We use getpid() to give us a persistent connection. */ function __construct() { global $c; if ( isset(self::$working) ) return; self::$working = false; if ( isset($c->memcache_servers) && class_exists('Memcached') ) { dbg_error_log('Cache', 'Using Memcached interface connection'); self::$servers = $c->memcache_servers; self::$m = new Memcached(); foreach( self::$servers AS $v ) { dbg_error_log('Cache', 'Adding server '.$v); $server = explode(',',$v); if ( isset($server[2]) ) self::$m->addServer($server[0],$server[1],$server[2]); else self::$m->addServer($server[0],$server[1]); } self::$working = true; // Hack to allow the regression tests to flush the cache at start if ( isset($_SERVER['HTTP_X_DAVICAL_FLUSH_CACHE'])) $this->flush(); } else { dbg_error_log('Cache', 'Using NoCache dummy interface'); } } /** * So we can find out if we are actually using the cache. */ function isActive() { return self::$working; } /** * Construct a string from the namespace & key * @param unknown_type $namespace * @param unknown_type $key */ private function nskey( $namespace, $key ) { return str_replace(' ', '%20', $namespace . (isset($key) ? '~~' . $key: '')); // for now. } /** * get a value from the specified namespace / key * @param $namespace * @param $key */ function get( $namespace, $key ) { if ( !self::$working ) return false; $ourkey = self::nskey($namespace,$key); $value = self::$m->get($ourkey); // var_dump($value); // if ( $value !== false ) dbg_error_log('Cache', 'Got value for cache key "'.$ourkey.'" - '.strlen(serialize($value)).' bytes'); return $value; } /** * Set a value for the specified namespace/key, perhaps with an expiry (default 10 days) * @param $namespace * @param $key * @param $value * @param $expiry */ function set( $namespace, $key, $value, $expiry=864000 ) { if ( !self::$working ) return false; $ourkey = self::nskey($namespace,$key); $nskey = self::nskey($namespace,null); $keylist = self::$m->get( $nskey, null, $cas_token ); if ( isset($keylist) && is_array($keylist) ) { if ( !isset($keylist[$ourkey]) ) { $keylist[$ourkey] = 1; $success = self::$m->cas( $cas_token, $nskey, $keylist ); $i=0; while( !$success && $i++ < 10 && self::$m->getResultCode() == Memcached::RES_DATA_EXISTS ) { $keylist = self::$m->get( $nskey, null, $cas_token ); if ( $keylist === false ) return false; if ( isset($keylist[$ourkey]) ) break; $keylist[$ourkey] = 1; $success = self::$m->cas( $cas_token, $nskey, $keylist ); } if ( !$success ) return false; } } else { $keylist = array( $ourkey => 1 ); self::$m->set( $nskey, $keylist ); } // var_dump($value); // dbg_error_log('Cache', 'Setting value for cache key "'.$ourkey.'" - '.strlen(serialize($value)).' bytes'); return self::$m->set( $ourkey, $value, $expiry ); } /** * Delete a value from a namespace/key, or for everything in a namespace if a 'null' key is supplied. * @param $namespace * @param $key */ function delete( $namespace, $key ) { if ( !self::$working ) return false; $nskey = self::nskey($namespace,$key); dbg_error_log('Cache', 'Deleting from cache key "'.$nskey.'"'); if ( isset($key) ) { self::$m->delete( $nskey ); } else { $keylist = self::$m->get( $nskey, null, $cas_token ); if ( isset($keylist) ) { self::$m->delete( $nskey ); if ( is_array($keylist) ) { foreach( $keylist AS $k => $v ) self::$m->delete( $k ); } } } } /** * Flush the entire cache */ function flush( ) { if ( !self::$working ) return false; dbg_error_log('Cache', 'Flushing cache'); self::$m->flush(); } /** * Acquire a lock on something */ function acquireLock( $something, $wait_for = 5 ) { if ( !self::$working ) return $something; $wait_until = time() + $wait_for; while( self::$m->add('_lock_'+$something,1,5) === false && time() < $wait_until ) { usleep(10000); } return $something; } /** * Release a lock */ function releaseLock( $something ) { if ( !self::$working ) return; self::$m->delete('_lock_'+$something); } } function getCacheInstance() { static $ourCacheInstance; if ( !isset($ourCacheInstance) ) $ourCacheInstance = new AWLCache('Memcached'); return $ourCacheInstance; }