public static function &connect_memcached($name) { static $insts = array(); if (isset($insts[$name])) { return $insts[$name]; } require_once 'MemcacheClient.php'; if (!isset(self::${$name})) { Logger::error("get connect_memcached:{$name} failed"); return false; } $inst = new MemcacheClient($name); //set some other option foreach (BasicConfig::${$name} as $h) { $inst->addServer($h[0], $h[1]); } $insts[$name] = $inst; return $inst; }
/** * Constructor. * @return void */ public function init() { $req = $this; $job = $this->job = new ComplexJob(function () use($req) { // called when job is done $req->wakeup(); // wake up the request immediately }); $memcache = MemcacheClient::getInstance(); $job('testquery', function ($name, $job) use($memcache) { // registering job named 'testquery' $memcache->stats(function ($memcache) use($name, $job) { // calling 'stats' $job->setResult($name, $memcache->result); // setting job result }); }); $job(); // let the fun begin $this->sleep(5, true); // setting timeout }
* under the License. * * @author mail@sachinpuri.com * @since 19/07/2015 */ include 'inc/app.php'; ?> <html> <head> <link rel="stylesheet" href="inc/main.css" /> <script type="text/javascript" src="inc/main.js"></script> </head> <body> <?php include "inc/header.php"; include "inc/nav.php"; if (isset($_GET['action'])) { if ($_GET['action'] != 'config') { $mem = new MemcacheClient($config['servers']); } include route($_GET['action']); } else { include "view/home.php"; } ?> </body> </html> <?php if (isset($mem)) { $mem->disconnect(); }