Author: Vasily Zorin (maintainer@daemon.io)
Inheritance: extends PHPDaemon\Network\Client
Example #1
0
 /**
  * Called when the worker is ready to go
  * @return void
  */
 public function onReady()
 {
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
     $this->redis->multi(function ($multi) {
         // "OK"
         D('start multi: ' . $multi->result);
         $multi->set('test1', 'value1', function ($redis) use($multi) {
             // "QUEUED"
             D('in multi 1: ' . $redis->result);
             $this->redis->set('test1', 'value1-new', function ($redis) {
                 // "OK", not "QUEUED"
                 D('out multi 1: ' . $redis->result);
             });
             setTimeout(function ($timer) use($multi) {
                 // "QUEUED"
                 $multi->set('test2', 'value2', function ($redis) use($multi) {
                     D('in multi 2: ' . $redis->result);
                     $multi->exec(function ($redis) {
                         D('exec');
                         D($redis->result);
                     });
                 });
                 $timer->free();
             }, 200000.0);
         });
     });
 }
Example #2
0
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
     /*$this->redis->eval("return {'a','b','c', {'d','e','f', {'g','h','i'}} }",0, function($redis) {
     			Daemon::log(Debug::dump($redis->result));
     		});*/
     $this->redis->subscribe('te3st', function ($redis) {
         Daemon::log(Debug::dump($redis->result));
     });
     $this->redis->psubscribe('test*', function ($redis) {
         Daemon::log(Debug::dump($redis->result));
     });
 }
Example #3
0
 /**
  * Called when the worker is ready to go
  * @return void
  */
 public function onReady()
 {
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
     $this->redis->hmset('myset', 'field1', 'value1', 'field2', 'value2', 'field3', 'value3', 'field4', 'value4', 'field5', 'value5', function ($redis) {
         $this->redis->hgetall('myset', function ($redis) {
             D('TEST 1: HGETALL');
             foreach ($redis as $key => $value) {
                 D($key . ' - ' . $value);
             }
             D($redis->assoc);
         });
         $this->redis->hmget('myset', 'field2', 'field4', function ($redis) {
             D('TEST 2: HMGET');
             foreach ($redis as $key => $value) {
                 D($key . ' - ' . $value);
             }
             D($redis->assoc);
         });
     });
     $this->redis->zadd('myzset', 100, 'one', 150, 'two', 325, 'three', function ($redis) {
         $this->redis->zrange('myzset', 0, -1, function ($redis) {
             D('TEST 3: ZRANGE');
             foreach ($redis as $key => $value) {
                 D($key . ' - ' . $value);
             }
             D($redis->assoc);
         });
         $this->redis->zrange('myzset', 0, -1, 'WITHSCORES', function ($redis) {
             D('TEST 4: ZRANGE WITHSCORES');
             foreach ($redis as $key => $value) {
                 D($key . ' - ' . $value);
             }
             D($redis->assoc);
         });
     });
     $this->redis->subscribe('mysub', function ($redis) {
         D('TEST 5: SUB & PUB');
         foreach ($redis as $key => $value) {
             D($key . ' - ' . $value);
         }
         D($redis->channel, $redis->msg, $redis->assoc);
     });
     $this->redis->publish('mysub', 'Test message!');
 }
Example #4
0
 /**
  * Called when the worker is ready to go
  * @return void
  */
 public function onReady()
 {
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
     $params = [];
     foreach (range(0, 100) as $i) {
         $params[] = 'myset' . $i;
         $params[] = 'value' . $i;
     }
     $params[] = function ($redis) {
         $params = [function ($redis) {
             D('Count: ' . count($redis->result[1]) . '; Next: ' . $redis->result[0]);
         }];
         $cbEnd = function ($redis, $scan) {
             D('Full scan end!');
         };
         // test 1
         // call_user_func_array([$this->redis, 'scan'], $params);
         // test 2
         $this->redis->autoscan('scan', $params, $cbEnd, 50);
     };
     call_user_func_array([$this->redis, 'mset'], $params);
 }
Example #5
0
 /**
  * Called when the worker is ready to go
  * @return void
  */
 public function onReady()
 {
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance($this->config->redisname->value);
     $this->sessions = new ObjectStorage();
     $this->wss = new ObjectStorage();
     foreach (preg_split('~\\s*;\\s*~', $this->config->wssname->value) as $wssname) {
         $this->attachWss(WebSocketPool::getInstance(trim($wssname)));
     }
 }
Example #6
0
 public function init()
 {
     Daemon::log(get_class($this) . ' up.');
     ini_set('display_errors', 'On');
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance($this->config->redisname->value);
     $this->db = \PHPDaemon\Clients\Mongo\Pool::getInstance($this->config->mongoname->value);
     $this->dbname = $this->config->dbname->value;
     $this->ipcId = new MongoId();
     $this->JobManager = new JobManager($this);
     $this->Sendmail = new Sendmail($this);
     if (isset($this->config->BackendServer)) {
         $this->backendServer = BackendServer::getInstance($this->config->BackendServer, true, $this);
     }
     if (isset($this->config->BackendClient)) {
         $this->backendClient = BackendClient::getInstance($this->config->BackendClient, true, $this);
     }
     $this->discoverOrm($this->config->ormdir->value . '*.php');
     /*	$this->LockClient = \PHPDaemon\Clients\Lock\Pool::getInstance();
     		$this->LockClient->job(get_class($this) . '-' . $this->name, true, function ($jobname, $command, $client) {
     			foreach (glob($this->config->themesdir->value . '*'.'/blocks/*') as $file) {
     				Daemon::$process->fileWatcher->addWatch($file, array($this, 'onBlockFileChanged'));
     			}
     		});*/
     $this->locales = array_map('basename', glob($this->config->localedir->value . '*', GLOB_ONLYDIR));
     if (!in_array($this->config->defaultlocale->value, $this->locales, true)) {
         $this->locales[] = $this->config->defaultlocale->value;
     }
     if (!in_array('en', $this->locales, true)) {
         $this->locales[] = 'en';
     }
     $this->components = new Components($this->fakeRequest());
     foreach ($this->config as $k => $c) {
         if (isset($c->run->value) && $c->run->value) {
             if (substr($k, 0, 3) === 'Cmp') {
                 $appInstance->components->{substr($k, 3)};
             }
         }
     }
     $this->serializer = 'igbinary';
     $this->httpclient = \PHPDaemon\Clients\HTTP\Pool::getInstance();
 }