예제 #1
0
파일: Swoole.php 프로젝트: abc1225/test2
 private function __construct()
 {
     if (!defined('DEBUG')) {
         define('DEBUG', 'on');
     }
     if (DEBUG == 'off') {
         \error_reporting(0);
     }
     $this->env['sapi_name'] = php_sapi_name();
     if ($this->env['sapi_name'] != 'cli') {
         Swoole\Error::$echo_html = true;
     }
     if (empty(self::$app_path)) {
         if (defined('WEBPATH')) {
             self::$app_path = WEBPATH . '/apps';
         } else {
             Swoole\Error::info("core error", __CLASS__ . ": Swoole::\$app_path and WEBPATH empty.");
         }
     }
     define('APPSPATH', self::$app_path);
     //将此目录作为App命名空间的根目录
     Swoole\Loader::addNameSpace('App', self::$app_path . '/classes');
     $this->load = new Swoole\Loader($this);
     $this->model = new Swoole\ModelLoader($this);
     $this->config = new Swoole\Config();
     $this->config->setPath(self::$app_path . '/configs');
     //路由钩子,URLRewrite
     $this->addHook(Swoole::HOOK_ROUTE, 'swoole_urlrouter_rewrite');
     //mvc
     $this->addHook(Swoole::HOOK_ROUTE, 'swoole_urlrouter_mvc');
     //设置路由函数
     $this->router(array($this, 'urlRoute'));
 }
예제 #2
0
 * @package SwooleSystem
 * @author 韩天峰
 */
define("LIBPATH", __DIR__);
if (PHP_OS == 'WINNT') {
    define("NL", "\r\n");
} else {
    define("NL", "\n");
}
define("BL", "<br />" . NL);
require_once __DIR__ . '/Swoole/Swoole.php';
require_once __DIR__ . '/Swoole/Loader.php';
/**
 * 注册顶层命名空间到自动载入器
 */
Swoole\Loader::addNameSpace('Swoole', __DIR__ . '/Swoole');
spl_autoload_register('\\Swoole\\Loader::autoload');
/**
 * 产生类库的全局变量
 */
global $php;
$php = Swoole::getInstance();
function createModel($model_name)
{
    return model($model_name);
}
/**
 * 生产一个model接口,模型在注册树上为单例
 * @param $model_name
 * @return Swoole\Model
 */
예제 #3
0
<?php

define("SWOOLEPATH", str_replace("\\", "/", __DIR__));
define("LIBPATH", SWOOLEPATH . '/../');
if (PHP_OS == 'WINNT') {
    define("NL", "\r\n");
} else {
    define("NL", "\n");
}
define("BL", "<br />" . NL);
require_once SWOOLEPATH . '/Loader.php';
/**
 * 注册顶层命名空间到自动载入器
 */
Swoole\Loader::setRootNS('Swoole', SWOOLEPATH);
spl_autoload_register('\\Swoole\\Loader::autoload');
예제 #4
0
define('DEBUG', 'on');
define("WEBPATH", str_replace("\\", "/", ROOT_PATH));
define('COMMON_PATH', __DIR__);
define('LIB_PATH', ROOT_PATH . DIRECTORY_SEPARATOR . 'lib');
//类库路径
define('HELPER_PATH', ROOT_PATH . DIRECTORY_SEPARATOR . 'helpers');
//类库路径helpers
define('LOG_PATH', ROOT_PATH . DIRECTORY_SEPARATOR . 'logs');
//日志路径
define('CONFIG_PATH', ROOT_PATH . DIRECTORY_SEPARATOR . 'config');
//配置文件目录
//config
$configFiles = glob(CONFIG_PATH . '/*config.php');
foreach ($configFiles as $file) {
    require_once $file;
}
//helpers
require_once HELPER_PATH . '/functions.php';
//lib
require_once LIB_PATH . '/Swoole/Swoole.php';
require_once LIB_PATH . '/Swoole/Loader.php';
/**
 * 注册顶层命名空间到自动载入器
 */
Swoole\Loader::addNameSpace('Swoole', LIB_PATH . '/Swoole');
spl_autoload_register('\\Swoole\\Loader::autoload');
/**
 * 产生类库的全局变量
 */
global $php;
$php = Swoole::getInstance();
예제 #5
0
<?php

define('DEBUG', 'on');
define('WEBPATH', __DIR__);
/**
 * /vendor/autoload.php是Composer工具生成的
 * shell: composer update
 */
require __DIR__ . '/vendor/autoload.php';
/**
 * Swoole框架自动载入器初始化
 */
Swoole\Loader::vendor_init();
/**
 * 注册命名空间到自动载入器中
 */
Swoole\Loader::addNameSpace('WebIM', __DIR__ . '/src/');
$config = (require __DIR__ . '/config.php');
$webim = new WebIM\Server($config);
$webim->loadSetting(__DIR__ . "/swoole.ini");
//加载配置文件
/**
 * webim必须使用swoole扩展
 */
$server = new Swoole\Network\Server($config['server']['host'], $config['server']['port']);
$server->setProtocol($webim);
$server->run($config['swoole']);
예제 #6
0
<?php

/**
 * sys_config.php.
 * Author: yeweijian
 * E-mail: yeweijian@hoolai.com
 * Date: 2016/1/15
 * Time: 15:48
 */
defined('LIB_PATH') or define('LIB_PATH', __DIR__);
defined('ROOT_PATH') or define('ROOT_PATH', dirname(LIB_PATH));
defined('APP_CONF_PATH') or define('APP_CONF_PATH', ROOT_PATH . '/config/app');
defined('SERVER_CONF_PATH') or define('SERVER_CONF_PATH', ROOT_PATH . '/config/server');
defined('RUNTIME_PATH') or define('RUNTIME_PATH', ROOT_PATH . '/runtime');
date_default_timezone_set('PRC');
require LIB_PATH . '/Swoole/Loader.php';
$loader = new \Swoole\Loader();
$loader->registerNamespace(['Swoole' => LIB_PATH . '/Swoole', 'EasyWork' => LIB_PATH . '/src', 'App' => ROOT_PATH . '/app'])->handle();
class EasyWork
{
    public static function createHttpServerHandler(array $config = [])
    {
        \Swoole\SysLog::init($config['log']);
        return new \Swoole\Protocol\Adapter\DefaultAdapter();
    }
}
예제 #7
0
<?php

if (!defined('SWOOLE_SERVER')) {
    define('DEBUG', 'on');
    define('WEBPATH', realpath(__DIR__ . '/../../'));
    require_once WEBPATH . '/vendor/autoload.php';
    Swoole\Loader::vendor_init();
    Swoole::$php->config->setPath(__DIR__ . '/configs');
}
/**
 * 用flash添加照片
 */
if ($_FILES) {
    global $php;
    $php->upload->thumb_width = 136;
    $php->upload->thumb_height = 136;
    $php->upload->thumb_qulitity = 100;
    $up_pic = $php->upload->save('Filedata');
    if (empty($up_pic)) {
        echo '上传失败,请重新上传! Error:' . $php->upload->error_msg;
    }
    echo json_encode($up_pic);
} else {
    echo "Bad Request\n";
}
 * @package SwooleSystem
 * @author 韩天峰
 */
define("LIBPATH", __DIR__);
if (PHP_OS == 'WINNT') {
    define("NL", "\r\n");
} else {
    define("NL", "\n");
}
define("BL", "<br />" . NL);
require_once __DIR__ . '/Swoole/Swoole.php';
require_once __DIR__ . '/Swoole/Loader.php';
/**
 * 注册顶层命名空间到自动载入器
 */
Swoole\Loader::setRootNS('Swoole', __DIR__ . '/Swoole');
spl_autoload_register('\\Swoole\\Loader::autoload');
/**
 * 产生类库的全局变量
 */
global $php;
$php = Swoole::getInstance();
/**
 *函数的命名空间
 */
function import_func($space_name)
{
    if ($space_name[0] == '@') {
        $func_file = WEBPATH . '/class/' . substr($space_name, 1) . '.func.php';
    } else {
        $func_file = LIBPATH . '/function/' . $space_name . '.php';
예제 #9
0
<?php

define('WEBPATH', __DIR__);
require_once __DIR__ . '/framework/libs/lib_config.php';
$env = get_cfg_var('env.name');
if (empty($env)) {
    $env = 'product';
}
define('ENV_NAME', $env);
Swoole::$php->config->setPath(__DIR__ . '/apps/configs/' . ENV_NAME);
Swoole\Loader::addNameSpace('NodeAgent', __DIR__ . '/NodeAgent');
예제 #10
0
<?php

/**
 *
 * @author: XuYi
 * @date: 2015-07-17
 * @version: $Id$
 */
define('DEBUG', 'on');
define('WEBPATH', __DIR__);
require __DIR__ . '/vendor/autoload.php';
Swoole\Loader::vendor_init();
Swoole\Loader::addNameSpace('WebPush', __DIR__ . '/src');
$config = (require __DIR__ . '/config.php');
$web_push = new WebPush\Demo_Server($config);
$web_push->loadSetting(__DIR__ . '/swoole.ini');
$web_push->setLogger(new \Swoole\Log\EchoLog(true));
//Logger
$server = new Swoole\Network\Server($config['server']['host'], $config['server']['port']);
$server->setProtocol($web_push);
$server->run($config['swoole']);
예제 #11
0
파일: start.php 프로젝트: vzina/esaywork
$cmd = $args['cmd'];
//cmd name
$name = $args['name'];
//需要cmd 和 name  name 支持 all 和 具体的serverName
if (!$cmd || !$name) {
    echo "please input cmd and server name: start all,start testserv ";
    exit;
}
try {
    //读取配置文件 然后启动对应的server
    $configPath = SERVER_CONF_PATH . '/' . $name . '.php';
    //获取配置地址
    // $config is file path? 提前读取 只读一次
    if (!file_exists($configPath)) {
        throw new Exception("[error] profiles [{$configPath}] can not be loaded");
    }
    $_config = Swoole\Loader::import($configPath);
    // Load the configuration file into an array
    //根据config里面的不同内容启动不同的server  定义网络层 UDP、TCP
    if (!($serverType = $_config['server']['type']) && !$serverType instanceof ServerAbstract) {
        throw new Exception("[error] server type error!");
    }
    /**
     * @var ServerAbstract $sysServer
     */
    $sysServer = new $serverType();
    $sysServer->setConfig($_config)->setCmd($cmd)->setProcessName($name)->setProtocol(EasyWork::createHttpServerHandler($_config))->run();
} catch (\Exception $e) {
    echo str_replace(ROOT_PATH, '', $e->getMessage()) . PHP_EOL;
    exit(1);
}
예제 #12
0
<?php

require __DIR__ . '/../../framework/libs/lib_config.php';
Swoole\Loader::addNameSpace('StatsCenter', __DIR__ . '/classes');
global $php;
$php = Swoole::getInstance();