1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/3/10
- * Time: 下午9:08
- */
- class fcgi_server
- {
- static private $stInstance = NULL;
- static public function instance()
- {
- if(self::$stInstance == NULL) {
- self::$stInstance = new fcgi_server();
- }
- return self::$stInstance;
- }
- private function is_exclude($file)
- {
- static $exfiles = array('wxnotify.php','alipay_notify_url.php','dispatch_notify.php','test.php');
- $name = basename($file);
- return in_array($name,$exfiles);
- }
- public function run_looper()
- {
- require_once(BASE_ROOT_PATH.'/mobile/index.php');
- Base::mobile_init();
- while(($ret = fcgi_accept()) >= 0)
- {
- ob_start();
- http_header::instance()->start();
- try
- {
- Log::start_sql_log();
- init_request();
- init_cookie($_SERVER['HTTP_COOKIE']);
- session::instance()->start();
- Log::record("req_uri = " . request_helper::req_uri(),Log::DEBUG);
- $file = request_helper::script_file();
- if(file_exists($file))
- {
- if(self::is_exclude($file)) {
- include $file;
- } else {
- fcgi_header("Content-Type: text/html; charset=UTF-8");
- Base::mobile_control();
- }
- }
- else
- {
- fcgi_header("Content-Type: text/html; charset=UTF-8");
- echo "no such file.";
- }
- }
- catch (TypeException $ex) {
- mobileControl::outerr($ex->getCode(),$ex->getMessage());
- }
- catch (Exception $ex) {
- mobileControl::outerr($ex->getCode(),$ex->getMessage());
- }
- fcgi_headers_sent();
- $contents = ob_get_clean();
- fcgi_echo($contents);
- session::instance()->end();
- fcgi_finish();
- }
- fcgi_fini();
- }
- }
|