* @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 */
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')); }
<?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']);
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();
<?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');
<?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']);
<?php require __DIR__ . '/../../framework/libs/lib_config.php'; Swoole\Loader::addNameSpace('StatsCenter', __DIR__ . '/classes'); global $php; $php = Swoole::getInstance();