Beispiel #1
0
<?php

$configs = \Swoole::$php->config['cache'];
if (empty($configs[\Swoole::$php->factory_key])) {
    throw new Swoole\Exception\Factory("cache->" . \Swoole::$php->factory_key . " is not found.");
}
return Swoole\Factory::getCache(Swoole::$php->factory_key);
Beispiel #2
0
<?php

// 自动加载器
include 'Swoole/AutoLoader.php';
define('APP_DEBUG', TRUE);
define('APP_PATH', './Application/');
// 实例化di容器
$di = new \Swoole\Factory();
// 获取服务器配置
$config = (include 'Config/configure.php');
$di->set('config', function () use($config) {
    return $config;
});
// 获取路由映射
$router = (include 'Config/router.php');
$di->set('router', function () use($router) {
    return $router;
});
// 注入redis缓存服务
$di->setShared('redis', function () {
    $redis = new \Swoole\Cache\Redis(array('host' => '127.0.0.1', 'port' => 6379, 'lifetime' => 10));
    return $redis;
});
// 注入mongo缓存服务
$di->set('mongo', function () {
    $mongo = new \Swoole\Cache\Mongo(array('server' => 'mongodb://127.0.0.1', 'db' => 'caches', 'collection' => 'image', 'lifetime' => 40));
    return $mongo;
});
// 注入swoole回调
// $di->set('onStart' , function (\swoole_server $serv){
// 	echo "Server is Running" . PHP_EOL;
<?php

if (empty(\Swoole::$php->config['cache']['master'])) {
    Swoole::$php->config['cache']['master'] = array('type' => 'FileCache', 'cache_dir' => WEBPATH . '/cache/filecache');
}
$cache = Swoole\Factory::getCache('master');
Beispiel #4
0
<?php

if (!empty(Swoole::$php->config['session']['use_swoole_session']) or defined('SWOOLE_SERVER')) {
    if (empty(Swoole::$php->config['cache']['session'])) {
        $cache = Swoole::$php->cache;
    } else {
        $cache = Swoole\Factory::getCache('session');
    }
    $session = new Swoole\Session($cache);
    $session->use_php_session = false;
} else {
    $session = new Swoole\Session();
}
return $session;