Автор: Vasily Zorin (maintainer@daemon.io)
Наследование: implements ArrayAccess, use trait PHPDaemon\Traits\ClassWatchdog, use trait PHPDaemon\Traits\StaticObjectWatchdog
Пример #1
0
    /**
     * Called when request iterated.
     * @return integer Status.
     */
    public function run()
    {
        try {
            $this->header('Content-Type: text/html');
        } catch (\Exception $e) {
        }
        ?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Clients\Redis Simple example</title>
</head>
<body>

<?php 
        if ($r = $this->job->getResult('testquery')) {
            echo '<h1>It works! Be happy! ;-)</h1>Result of query: <pre>';
            var_dump($r);
            echo '</pre>';
        } else {
            echo '<h1>Something went wrong! We have no result.</h1>';
        }
        echo '<br />Request (http) took: ' . round(microtime(TRUE) - $this->attrs->server['REQUEST_TIME_FLOAT'], 6);
        ?>
</body>
</html>

<?php 
    }
Пример #2
0
 protected function sessionStartNew($cb = null)
 {
     $job = new ComplexJob(function () use(&$job, $cb) {
         $session = $this->appInstance->sessions->startSession(['ip' => $this->getIp(), 'atime' => time(), 'expires' => time() + $this->defaultSessionTTL, 'ttl' => $this->defaultSessionTTL, 'browser' => ['agent' => $this->browser['_id'], 'os' => $this->browser['platform'], 'name' => $this->browser['name'], 'majorver' => $this->browser['majorver'], 'comment' => $this->browser['comment'], 'ismobiledevice' => $this->browser['ismobiledevice']], 'location' => $job->getResult('geoip')], function ($lastError) use(&$session, $cb) {
             if (!$session) {
                 if ($cb !== null) {
                     call_user_func($cb, false);
                 }
                 return;
             }
             $this->sessionId = (string) $session['id'];
             $this->attrs->session = $session;
             try {
                 $this->setcookie(ini_get('session.name'), $this->sessionId, ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), $this->appInstance->config->cookiedomain->value ?: ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
             } finally {
                 call_user_func($cb, true);
             }
         });
     });
     $job('browser', function ($jobname, $job) {
         $this->getBrowser(function () use($jobname, $job) {
             $job->setResult($jobname);
         });
     });
     $job('geoip', function ($jobname, $job) {
         $this->appInstance->geoIP->query($this->getIp(true), function ($loc) use($jobname, $job) {
             $job->setResult($jobname, $loc);
         });
     });
     $job();
 }