├── README.md ├── application ├── Bootstrap.php ├── controllers │ ├── Error.php │ └── Index.php ├── library │ ├── Base │ │ └── Controllers.php │ └── HttpServer.php └── views │ ├── error.phtml │ └── index.phtml ├── conf ├── application.ini └── server.ini ├── patch ├── yaf-2.3.5-swoole.zip └── yaf.patch.20151023 └── server.php /README.md: -------------------------------------------------------------------------------- 1 | # **Swoole-Yaf** # 2 | --- 3 | 将Yaf框架和Swoole扩展提供的HttpServer结合在一起,server和框架高度结合形成超高性能的组合 4 | 5 | ## **修改说明** ## 6 | --- 7 | Yaf经过二次开发得以与Swoole完美融合,具体修改和添加包括两部分 8 | 9 | 1. Yaf源码修改:请查看patch文件夹中的patch文件 10 | 2. 二次封装 11 | 12 | application/library/HttpServer.php 13 | application/Base/Controllers.php 14 | 15 | 16 | 17 | ##**作者**## 18 | --- 19 | 20 | 花生[wenjun1055@gmail.com] 21 | 22 | ##**使用**## 23 | --- 24 | 25 | 打开终端 26 | cd swoole-yaf 27 | php server.php 28 | 29 | 打开浏览器,输入http://127.0.0.1:8080 30 | 31 | 32 | ##**版本要求**## 33 | --- 34 | 35 | [Swoole](https://github.com/swoole/swoole-src) 1.7.8+ 36 | 37 | [Yaf](https://github.com/laruence/yaf) 任意stable版本 38 | 39 | 40 | ##**注意**## 41 | --- 42 | 43 | 各位Star、Fork的时候,麻烦Follow一下,谢谢 [https://github.com/wenjun1055](https://github.com/wenjun1055) -------------------------------------------------------------------------------- /application/Bootstrap.php: -------------------------------------------------------------------------------- 1 | 16 | * @param Yaf_Dispatcher $dispatcher 17 | * 18 | * @return void 19 | */ 20 | public function _initConfig(Yaf_Dispatcher $dispatcher) 21 | { 22 | Yaf_Registry::set('config', Yaf_Application::app()->getConfig()); 23 | 24 | $dispatcher->disableView(); 25 | } 26 | 27 | /** 28 | * Method _initLocalNamespace 29 | * @desc ...... 30 | * 31 | * @author WenJun 32 | * 33 | * @return void 34 | */ 35 | public function _initLocalNamespace() 36 | { 37 | $namespace = array( 38 | 'Base', 39 | ); 40 | Yaf_Loader::getInstance()->registerLocalNamespace($namespace); 41 | } 42 | 43 | /** 44 | * Method _initRoute 45 | * @desc ...... 46 | * 47 | * @author WenJun 48 | * @param Yaf_Dispatcher $dispatcher 49 | * 50 | * @return void 51 | */ 52 | public function _initRoute(Yaf_Dispatcher $dispatcher) 53 | { 54 | // $oRouter = Yaf_Dispatcher::getInstance()->getRouter(); 55 | // $result = $oRouter->addConfig(Yaf_Registry::get('config')->routes); 56 | } 57 | } -------------------------------------------------------------------------------- /application/controllers/Error.php: -------------------------------------------------------------------------------- 1 | 16 | * @param null $exception 17 | * 18 | * @return void 19 | */ 20 | public function errorAction($exception = null) 21 | { 22 | header("HTTP/1.1 404 Not Found"); 23 | //3秒后跳去首页 24 | header("refresh:3;url=/"); 25 | 26 | $this->getView()->display('error.phtml'); 27 | } 28 | } -------------------------------------------------------------------------------- /application/controllers/Index.php: -------------------------------------------------------------------------------- 1 | 16 | * 17 | * @return void 18 | */ 19 | public function indexAction() 20 | { 21 | var_dump($this->getServer()); 22 | var_dump($this->getHeader()); 23 | var_dump($this->getQuery()); 24 | var_dump($this->getPost()); 25 | var_dump($this->getCookie()); 26 | var_dump($this->getFiles()); 27 | var_dump($this->getRawContent()); 28 | 29 | $this->getView()->display('index.phtml'); 30 | } 31 | } -------------------------------------------------------------------------------- /application/library/Base/Controllers.php: -------------------------------------------------------------------------------- 1 | 18 | * @param null $param 19 | * @return bool|mixed 20 | */ 21 | public function getServer($param = null) 22 | { 23 | $server = Yaf_Registry::get('REQUEST_SERVER'); 24 | 25 | if (null === $param) { 26 | return $server; 27 | } 28 | 29 | if (isset($server[$param])) { 30 | return $server[$param]; 31 | } 32 | 33 | return false; 34 | } 35 | 36 | /** 37 | * Method getHeader 38 | * @desc _HEADER 39 | * http://wiki.swoole.com/wiki/page/332.html 40 | * @author WenJun 41 | * @param null $param 42 | * @return bool|mixed 43 | */ 44 | public function getHeader($param = null) 45 | { 46 | $header = Yaf_Registry::get('REQUEST_HEADER'); 47 | 48 | if (null === $param) { 49 | return $header; 50 | } 51 | 52 | if (isset($header[$param])) { 53 | return $header[$param]; 54 | } 55 | 56 | return false; 57 | } 58 | 59 | /** 60 | * Method getQuery 61 | * @desc _GET 62 | * http://wiki.swoole.com/wiki/page/333.html 63 | * @author WenJun 64 | * @param null $param 65 | * @return bool|mixed 66 | */ 67 | public function getQuery($param = null) 68 | { 69 | $get = Yaf_Registry::get('REQUEST_GET'); 70 | 71 | if (null === $param) { 72 | return $get; 73 | } 74 | 75 | if (isset($get[$param])) { 76 | return $get[$param]; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | /** 83 | * Method getPost 84 | * @desc _POST 85 | * http://wiki.swoole.com/wiki/page/334.html 86 | * @author WenJun 87 | * @param null $param 88 | * @return bool|mixed 89 | */ 90 | public function getPost($param = null) 91 | { 92 | $post = Yaf_Registry::get('REQUEST_POST'); 93 | 94 | if (null === $param) { 95 | return $post; 96 | } 97 | 98 | if (isset($post[$param])) { 99 | return $post[$param]; 100 | } 101 | 102 | return false; 103 | } 104 | 105 | /** 106 | * Method getCookie 107 | * @desc _COOKIE 108 | * http://wiki.swoole.com/wiki/page/335.html 109 | * @author WenJun 110 | * @param null $param 111 | * @return bool|mixed 112 | */ 113 | public function getCookie($param = null) 114 | { 115 | $cookie = Yaf_Registry::get('REQUEST_COOKIE'); 116 | 117 | if (null === $param) { 118 | return $cookie; 119 | } 120 | 121 | if (isset($cookie[$param])) { 122 | return $cookie[$param]; 123 | } 124 | 125 | return false; 126 | } 127 | 128 | /** 129 | * Method getFiles 130 | * @desc _FILES 131 | * http://wiki.swoole.com/wiki/page/428.html 132 | * @author WenJun 133 | * @param null $param 134 | * @return bool|mixed 135 | */ 136 | public function getFiles($param = null) 137 | { 138 | $files = Yaf_Registry::get('REQUEST_FILES'); 139 | 140 | if (null === $param) { 141 | return $files; 142 | } 143 | 144 | if (isset($files[$param])) { 145 | return $files[$param]; 146 | } 147 | 148 | return false; 149 | } 150 | 151 | /** 152 | * Method getRawContent 153 | * @desc raw_content 154 | * http://wiki.swoole.com/wiki/page/375.html 155 | * @author WenJun 156 | * @return mixed 157 | */ 158 | public function getRawContent() 159 | { 160 | return Yaf_Registry::get('REQUEST_RAW_CONTENT'); 161 | } 162 | 163 | /** 164 | * Method setHeader 165 | * @desc 设置header 166 | * http://wiki.swoole.com/wiki/page/336.html 167 | * 168 | * @author WenJun 169 | * @param $key 170 | * @param $value 171 | * 172 | * @return bool 173 | */ 174 | public function setHeader($key, $value) 175 | { 176 | if (empty($key) && empty($value)) { 177 | return false; 178 | } 179 | 180 | $responseObj = Yaf_Registry::get('SWOOLE_HTTP_RESPONSE'); 181 | return $responseObj->header($key, $value); 182 | } 183 | 184 | /** 185 | * Method setCookie 186 | * @desc 设置cookie 187 | * http://wiki.swoole.com/wiki/page/337.html 188 | * 189 | * @author WenJun 190 | * @param $key 191 | * @param string $value 192 | * @param int $expire 193 | * @param string $path 194 | * @param string $domain 195 | * @param bool $secure 196 | * @param bool $httponly 197 | * 198 | * @return bool 199 | */ 200 | public function setCookie($key, $value = '', $expire = 0, $path = '/', 201 | $domain = '', $secure = false, $httponly = false) 202 | { 203 | if (empty($key)) { 204 | return false; 205 | } 206 | 207 | $responseObj = Yaf_Registry::get('SWOOLE_HTTP_RESPONSE'); 208 | return $responseObj->cookie($key, $value, $expire, $path, $domain, $secure, $httponly); 209 | } 210 | 211 | /** 212 | * Method setHttpCode 213 | * @desc 设置http_code 214 | * http://wiki.swoole.com/wiki/page/338.html 215 | * 216 | * @author WenJun 217 | * @param $code 218 | * 219 | * @return bool 220 | */ 221 | public function setHttpCode($code) 222 | { 223 | if (empty($code) || $code < 0) { 224 | return false; 225 | } 226 | 227 | $responseObj = Yaf_Registry::get('SWOOLE_HTTP_RESPONSE'); 228 | return $responseObj->status($code); 229 | } 230 | 231 | /** 232 | * Method setGzip 233 | * @desc 设置压缩比例 234 | * http://wiki.swoole.com/wiki/page/410.html 235 | * 236 | * @author WenJun 237 | * @param int $level 238 | * 239 | * @return bool 240 | */ 241 | public function setGzip($level = 1) 242 | { 243 | $level = intval($level); 244 | if ($level < 1 || $level > 9) { 245 | return false; 246 | } 247 | 248 | $responseObj = Yaf_Registry::get('SWOOLE_HTTP_RESPONSE'); 249 | return $responseObj->gzip($level); 250 | } 251 | } -------------------------------------------------------------------------------- /application/library/HttpServer.php: -------------------------------------------------------------------------------- 1 | 16 | * @var string 17 | */ 18 | private $defaultIp = '0.0.0.0'; 19 | 20 | /** 21 | * Variable defaultPort 22 | * 默认监听绑定端口 23 | * @author WenJun 24 | * @var int 25 | */ 26 | private $defaultPort = 8080; 27 | 28 | /** 29 | * Variable serverConfig 30 | * @author WenJun 31 | * @var 32 | */ 33 | private $serverConfig; 34 | 35 | /** 36 | * Variable appConfigFile 37 | * @author WenJun 38 | * @var 39 | */ 40 | private $appConfigFile; 41 | 42 | /** 43 | * Variable serverObj 44 | * @author WenJun 45 | * @var 46 | */ 47 | private $serverObj; 48 | 49 | /** 50 | * Variable yafAppObj 51 | * @author WenJun 52 | * @var 53 | */ 54 | private $yafAppObj; 55 | 56 | /** 57 | * Variable instance 58 | * @author WenJun 59 | * @static 60 | * @var null 61 | */ 62 | protected static $instance = null; 63 | 64 | /** 65 | * Method getInstance 66 | * @desc 获取对象 67 | * @author WenJun 68 | * @static 69 | * @return HttpServer|null 70 | */ 71 | public static function getInstance() 72 | { 73 | if (empty(self::$instance) || !(self::$instance instanceof HttpServer)) { 74 | self::$instance = new self(); 75 | } 76 | 77 | return self::$instance; 78 | } 79 | 80 | /** 81 | * __construct 82 | */ 83 | private function __construct() 84 | { 85 | } 86 | 87 | /** 88 | * Method setServerConfigIni 89 | * @desc 设置server_config 90 | * @author WenJun 91 | * @param $serverConfigIni 92 | * @return void 93 | */ 94 | public function setServerConfigIni($serverConfigIni) 95 | { 96 | if (!is_file($serverConfigIni)) { 97 | trigger_error('Server Config File Not Exist!', E_USER_ERROR); 98 | } 99 | 100 | $serverConfig = parse_ini_file($serverConfigIni, true); 101 | if (empty($serverConfig)) { 102 | trigger_error('Server Config Content Empty!', E_USER_ERROR); 103 | } 104 | 105 | $this->serverConfig = $serverConfig; 106 | } 107 | 108 | /** 109 | * Method setAppConfigIni 110 | * @desc ...... 111 | * @author WenJun 112 | * @param $appConfigIni 113 | * @return void 114 | */ 115 | public function setAppConfigIni($appConfigIni) 116 | { 117 | if (!is_file($appConfigIni)) { 118 | trigger_error('Server Config File Not Exist!', E_USER_ERROR); 119 | } 120 | 121 | $this->appConfigFile = $appConfigIni; 122 | } 123 | 124 | /** 125 | * Method start 126 | * @desc 启动server 127 | * @author WenJun 128 | * @return void 129 | */ 130 | public function start() 131 | { 132 | $ip = isset($this->serverConfig['server']['ip']) ? $this->serverConfig['server']['ip'] : $this->defaultIp; 133 | $port = isset($this->serverConfig['server']['port']) ? $this->serverConfig['server']['port'] : $this->defaultPort; 134 | 135 | $this->serverObj = new swoole_http_server($ip, $port); 136 | $this->serverObj->set($this->serverConfig['swoole']); 137 | $this->serverObj->on('Start', array($this, 'onStart')); 138 | $this->serverObj->on('ManagerStart', array($this, 'onManagerStart')); 139 | $this->serverObj->on('WorkerStart', array($this, 'onWorkerStart')); 140 | $this->serverObj->on('WorkerStop', array($this, 'onWorkerStop')); 141 | $this->serverObj->on('request', array($this, 'onRequest')); 142 | $this->serverObj->start(); 143 | } 144 | 145 | /** 146 | * Method onStart 147 | * @desc master start 148 | * 149 | * @author WenJun 150 | * @param swoole_http_server $serverObj 151 | * 152 | * @return bool 153 | */ 154 | public function onStart(swoole_http_server $serverObj) 155 | { 156 | //rename 157 | swoole_set_process_name($this->serverConfig['server']['master_process_name']); 158 | 159 | return true; 160 | } 161 | 162 | /** 163 | * Method onManagerStart 164 | * @desc manager process start 165 | * 166 | * @author WenJun 167 | * @param swoole_http_server $serverObj 168 | * 169 | * @return bool 170 | */ 171 | public function onManagerStart(swoole_http_server $serverObj) 172 | { 173 | //rename 174 | swoole_set_process_name($this->serverConfig['server']['manager_process_name']); 175 | 176 | return true; 177 | } 178 | 179 | /** 180 | * Method onWorkerStart 181 | * @desc worker process start 182 | * @author WenJun 183 | * @param swoole_http_server $server 184 | * @param $workerId 185 | * @return bool 186 | */ 187 | public function onWorkerStart(swoole_http_server $serverObj, $workerId) 188 | { 189 | //rename 190 | $processName = sprintf($this->serverConfig['server']['event_worker_process_name'], $workerId); 191 | swoole_set_process_name($processName); 192 | 193 | //实例化yaf 194 | $this->yafAppObj = new Yaf_Application($this->appConfigFile); 195 | 196 | return true; 197 | } 198 | 199 | /** 200 | * Method onWorkerStop 201 | * @desc worker process stop 202 | * 203 | * @author WenJun 204 | * @param swoole_http_server $serverObj 205 | * @param $workerId 206 | * 207 | * @return bool 208 | */ 209 | public function onWorkerStop(swoole_http_server $serverObj, $workerId) 210 | { 211 | return true; 212 | } 213 | 214 | /** 215 | * Method onRequest 216 | * @desc http 请求部分 217 | * @author WenJun 218 | * @param swoole_http_request $request 219 | * @param swoole_http_response $response 220 | * @return void 221 | */ 222 | public function onRequest(swoole_http_request $request, swoole_http_response $response) 223 | { 224 | //清理环境 225 | Yaf_Registry::flush(); 226 | Yaf_Dispatcher::destoryInstance(); 227 | 228 | //注册全局信息 229 | $this->initRequestParam($request); 230 | Yaf_Registry::set('SWOOLE_HTTP_REQUEST', $request); 231 | Yaf_Registry::set('SWOOLE_HTTP_RESPONSE', $response); 232 | 233 | //执行 234 | ob_start(); 235 | try { 236 | $requestObj = new Yaf_Request_Http($request->server['request_uri']); 237 | 238 | $configArr = Yaf_Application::app()->getConfig()->toArray(); 239 | if (!empty($configArr['application']['baseUri'])) { //set base_uri 240 | $requestObj->setBaseUri($configArr['application']['baseUri']); 241 | } 242 | 243 | $this->yafAppObj->bootstrap()->getDispatcher()->dispatch($requestObj); 244 | } catch (Yaf_Exception $e) { 245 | var_dump($e); 246 | } 247 | 248 | $result = ob_get_contents(); 249 | ob_end_clean(); 250 | 251 | $response->end($result); 252 | } 253 | 254 | /** 255 | * Method initRequestParam 256 | * @desc 将请求信息放入全局注册器中 257 | * @author WenJun 258 | * @param swoole_http_request $request 259 | * @return bool 260 | */ 261 | private function initRequestParam(swoole_http_request $request) 262 | { 263 | //将请求的一些环境参数放入全局变量桶中 264 | $server = isset($request->server) ? $request->server : array(); 265 | $header = isset($request->header) ? $request->header : array(); 266 | $get = isset($request->get) ? $request->get : array(); 267 | $post = isset($request->post) ? $request->post : array(); 268 | $cookie = isset($request->cookie) ? $request->cookie : array(); 269 | $files = isset($request->files) ? $request->files : array(); 270 | 271 | Yaf_Registry::set('REQUEST_SERVER', $server); 272 | Yaf_Registry::set('REQUEST_HEADER', $header); 273 | Yaf_Registry::set('REQUEST_GET', $get); 274 | Yaf_Registry::set('REQUEST_POST', $post); 275 | Yaf_Registry::set('REQUEST_COOKIE', $cookie); 276 | Yaf_Registry::set('REQUEST_FILES', $files); 277 | Yaf_Registry::set('REQUEST_RAW_CONTENT', $request->rawContent()); 278 | 279 | return true; 280 | } 281 | } -------------------------------------------------------------------------------- /application/views/error.phtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | error 6 | 7 | 8 |

Error

9 | 10 | -------------------------------------------------------------------------------- /application/views/index.phtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | swoole-yaf 6 | 7 | 8 |

Hello Swoole-Yaf

9 | 10 | -------------------------------------------------------------------------------- /conf/application.ini: -------------------------------------------------------------------------------- 1 | [common] 2 | application.directory = APPLICATION_PATH 3 | application.dispatcher.throwException = 1 4 | application.dispatcher.catchException = 1 5 | 6 | application.bootstrap = APPLICATION_PATH"/Bootstrap.php" 7 | application.library = APPLICATION_PATH"/library" 8 | application.models = APPLICATION_PATH"/models" 9 | 10 | 11 | application.dispatcher.defaultModule = "Index" 12 | application.dispatcher.defaultController = "Index" 13 | application.dispatcher.defaultAction = "index" 14 | application.modules = "Index" 15 | 16 | application.baseUri = "/base_uri" 17 | application.ext = "php" 18 | 19 | [product : common] 20 | -------------------------------------------------------------------------------- /conf/server.ini: -------------------------------------------------------------------------------- 1 | [swoole] 2 | dispatch_mode=3 3 | worker_num=1 4 | log_file=/home/work/wenjun/yaf-swoole/logs/swoole.log 5 | 6 | [server] 7 | port=8899 8 | programname=swoole-yaf 9 | master_process_name=swoole-yaf-master 10 | manager_process_name=swoole-yaf-manager 11 | event_worker_process_name=swoole-yaf-evnet-worker-%d -------------------------------------------------------------------------------- /patch/yaf-2.3.5-swoole.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenjun1055/swoole-yaf/7dabdf67858bb088941565c6b9c95b5e3b2a0761/patch/yaf-2.3.5-swoole.zip -------------------------------------------------------------------------------- /patch/yaf.patch.20151023: -------------------------------------------------------------------------------- 1 | diff --git a/yaf_application.c b/yaf_application.c 2 | index 6849bfb..b1f6381 100644 3 | --- a/yaf_application.c 4 | +++ b/yaf_application.c 5 | @@ -314,7 +314,7 @@ static int yaf_application_parse_option(zval *options TSRMLS_DC) { 6 | PHP_METHOD(yaf_application, __construct) { 7 | yaf_config_t *zconfig; 8 | yaf_request_t *request; 9 | - yaf_dispatcher_t *zdispatcher; 10 | +// yaf_dispatcher_t *zdispatcher; 11 | yaf_application_t *app, *self; 12 | yaf_loader_t *loader; 13 | zval *config; 14 | @@ -357,33 +357,33 @@ PHP_METHOD(yaf_application, __construct) { 15 | RETURN_FALSE; 16 | } 17 | 18 | - request = yaf_request_instance(NULL, YAF_G(base_uri) TSRMLS_CC); 19 | - if (YAF_G(base_uri)) { 20 | - efree(YAF_G(base_uri)); 21 | - YAF_G(base_uri) = NULL; 22 | - } 23 | - 24 | - if (!request) { 25 | - YAF_UNINITIALIZED_OBJECT(getThis()); 26 | - yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Initialization of request failed"); 27 | - RETURN_FALSE; 28 | - } 29 | - 30 | - zdispatcher = yaf_dispatcher_instance(NULL TSRMLS_CC); 31 | - if (NULL == zdispatcher 32 | - || Z_TYPE_P(zdispatcher) != IS_OBJECT 33 | - || !instanceof_function(Z_OBJCE_P(zdispatcher), yaf_dispatcher_ce TSRMLS_CC)) { 34 | - YAF_UNINITIALIZED_OBJECT(getThis()); 35 | - yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Instantiation of application dispatcher failed"); 36 | - RETURN_FALSE; 37 | - } 38 | - yaf_dispatcher_set_request(zdispatcher, request TSRMLS_CC); 39 | +// request = yaf_request_instance(NULL, YAF_G(base_uri) TSRMLS_CC); 40 | +// if (YAF_G(base_uri)) { 41 | +// efree(YAF_G(base_uri)); 42 | +// YAF_G(base_uri) = NULL; 43 | +// } 44 | +// 45 | +// if (!request) { 46 | +// YAF_UNINITIALIZED_OBJECT(getThis()); 47 | +// yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Initialization of request failed"); 48 | +// RETURN_FALSE; 49 | +// } 50 | +// 51 | +// zdispatcher = yaf_dispatcher_instance(NULL TSRMLS_CC); 52 | +// if (NULL == zdispatcher 53 | +// || Z_TYPE_P(zdispatcher) != IS_OBJECT 54 | +// || !instanceof_function(Z_OBJCE_P(zdispatcher), yaf_dispatcher_ce TSRMLS_CC)) { 55 | +// YAF_UNINITIALIZED_OBJECT(getThis()); 56 | +// yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Instantiation of application dispatcher failed"); 57 | +// RETURN_FALSE; 58 | +// } 59 | +// yaf_dispatcher_set_request(zdispatcher, request TSRMLS_CC); 60 | 61 | zend_update_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_CONFIG), zconfig TSRMLS_CC); 62 | - zend_update_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), zdispatcher TSRMLS_CC); 63 | +// zend_update_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), zdispatcher TSRMLS_CC); 64 | 65 | - zval_ptr_dtor(&request); 66 | - zval_ptr_dtor(&zdispatcher); 67 | +// zval_ptr_dtor(&request); 68 | +// zval_ptr_dtor(&zdispatcher); 69 | zval_ptr_dtor(&zconfig); 70 | 71 | if (YAF_G(local_library)) { 72 | @@ -572,7 +572,8 @@ PHP_METHOD(yaf_application, getConfig) { 73 | /** {{{ proto public Yaf_Application::getDispatcher(void) 74 | */ 75 | PHP_METHOD(yaf_application, getDispatcher) { 76 | - yaf_dispatcher_t *dispatcher = zend_read_property(yaf_application_ce, getThis(), ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), 1 TSRMLS_CC); 77 | + yaf_dispatcher_t *dispatcher = yaf_dispatcher_instance(NULL TSRMLS_CC); 78 | +// yaf_dispatcher_t *dispatcher = zend_read_property(yaf_application_ce, getThis(), ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), 1 TSRMLS_CC); 79 | RETVAL_ZVAL(dispatcher, 1, 0); 80 | } 81 | /* }}} */ 82 | @@ -632,7 +633,8 @@ PHP_METHOD(yaf_application, bootstrap) { 83 | 84 | MAKE_STD_ZVAL(bootstrap); 85 | object_init_ex(bootstrap, *ce); 86 | - dispatcher = zend_read_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), 1 TSRMLS_CC); 87 | + dispatcher = yaf_dispatcher_instance(NULL TSRMLS_CC); 88 | +// dispatcher = zend_read_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), 1 TSRMLS_CC); 89 | 90 | methods = &((*ce)->function_table); 91 | for(zend_hash_internal_pointer_reset(methods); 92 | diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c 93 | index 004a172..8b6800d 100644 94 | --- a/yaf_dispatcher.c 95 | +++ b/yaf_dispatcher.c 96 | @@ -1124,6 +1124,15 @@ PHP_METHOD(yaf_dispatcher, getInstance) { 97 | } 98 | /* }}} */ 99 | 100 | +/** {{{ proto public Yaf_Dispatcher::destoryInstance(void) 101 | +*/ 102 | +PHP_METHOD(yaf_dispatcher, destoryInstance) { 103 | + zend_update_static_property_null(yaf_dispatcher_ce, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_INSTANCE) TSRMLS_CC); 104 | + 105 | + RETURN_TRUE; 106 | +} 107 | +/* }}} */ 108 | + 109 | /** {{{ proto public Yaf_Dispatcher::getRouter(void) 110 | */ 111 | PHP_METHOD(yaf_dispatcher, getRouter) { 112 | @@ -1371,6 +1380,7 @@ zend_function_entry yaf_dispatcher_methods[] = { 113 | PHP_ME(yaf_dispatcher, throwException, yaf_dispatcher_throwex_arginfo, ZEND_ACC_PUBLIC) 114 | PHP_ME(yaf_dispatcher, catchException, yaf_dispatcher_catchex_arginfo, ZEND_ACC_PUBLIC) 115 | PHP_ME(yaf_dispatcher, registerPlugin, yaf_dispatcher_regplugin_arginfo, ZEND_ACC_PUBLIC) 116 | + PHP_ME(yaf_dispatcher, destoryInstance, yaf_dispatcher_void_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) 117 | {NULL, NULL, NULL} 118 | }; 119 | /* }}} */ 120 | diff --git a/yaf_registry.c b/yaf_registry.c 121 | index da0cde1..13f279a 100644 122 | --- a/yaf_registry.c 123 | +++ b/yaf_registry.c 124 | @@ -187,6 +187,23 @@ PHP_METHOD(yaf_registry, getInstance) { 125 | } 126 | /* }}} */ 127 | 128 | +/** {{{ proto public Yaf_Registry::flush(void) 129 | +*/ 130 | +PHP_METHOD(yaf_registry, flush) { 131 | + yaf_registry_t *instance; 132 | + zval *regs; 133 | + 134 | + instance = yaf_registry_instance(NULL TSRMLS_CC); 135 | + 136 | + MAKE_STD_ZVAL(regs); 137 | + array_init(regs); 138 | + zend_update_property(yaf_registry_ce, instance, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), regs TSRMLS_CC); 139 | + zval_ptr_dtor(®s); 140 | + 141 | + RETURN_TRUE; 142 | +} 143 | +/* }}} */ 144 | + 145 | /** {{{ yaf_registry_methods 146 | */ 147 | zend_function_entry yaf_registry_methods[] = { 148 | @@ -196,6 +213,7 @@ zend_function_entry yaf_registry_methods[] = { 149 | PHP_ME(yaf_registry, has, yaf_registry_has_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 150 | PHP_ME(yaf_registry, set, yaf_registry_set_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 151 | PHP_ME(yaf_registry, del, yaf_registry_del_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 152 | + PHP_ME(yaf_registry, flush, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 153 | {NULL, NULL, NULL} 154 | }; 155 | /* }}} */ 156 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | setServerConfigIni(CONF_PATH . DS . 'server.ini'); 23 | $serverObj->setAppConfigIni(CONF_PATH . DS . 'application.ini'); 24 | $serverObj->start(); 25 | --------------------------------------------------------------------------------