|
@@ -0,0 +1,154 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: stanley-king
|
|
|
+ * Date: 16/3/10
|
|
|
+ * Time: 下午9:08
|
|
|
+ */
|
|
|
+
|
|
|
+require_once (BASE_ROOT_PATH . '/mobile/index.php');
|
|
|
+require_once (BASE_ROOT_PATH . '/helper/area_helper.php');
|
|
|
+require_once (BASE_CORE_PATH . '/framework/function/http.php');
|
|
|
+
|
|
|
+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 = ['web_wxnotify.php',
|
|
|
+ 'wxnotify.php','pub_wxnotify.php','alipay_notify_url.php','dispatch_notify.php','kdniao_notify.php',
|
|
|
+ 'cmbpay_notify.php','cmbpay_sign.php','wxauthor.php','api/wxLogin/index.php','api/wxLogin/callback.php',
|
|
|
+ 'signature.php',
|
|
|
+ 'refill_tianjt.php','refill_suhctm.php','refill_suhcpdd.php','refill_gftd.php',
|
|
|
+ 'refill_beixt.php','refill_bxtwt.php','refill_bjb.php','refill_xyz.php',
|
|
|
+ 'refill_zzx.php','refill_inner.php','refill_jiec.php','refill_yifa.php',
|
|
|
+ 'bridge_shr.php','refill_weit.php','refill_tianx.php','refill_afand.php',
|
|
|
+ 'refill_afandeng.php'
|
|
|
+ ];
|
|
|
+ $path = BASE_ROOT_PATH . '/mobile/';
|
|
|
+ $file = str_replace($path,'',$file);
|
|
|
+
|
|
|
+ return in_array($file,$exfiles);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function clear_global()
|
|
|
+ {
|
|
|
+ $_SESSION = [];
|
|
|
+ $_COOKIE = [];
|
|
|
+ $_POST = [];
|
|
|
+ $_GET = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function handle_error($level, $message, $file, $line)
|
|
|
+ {
|
|
|
+ if($level == E_NOTICE) return;
|
|
|
+ $trace = "handle_error: level={$level},msg={$message} file={$file},line={$line}\n";
|
|
|
+ $backtrace = debug_backtrace();
|
|
|
+ foreach ($backtrace as $item) {
|
|
|
+ $trace .= "{$item['file']}\t{$item['line']}\t{$item['function']}\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ Log::record($trace,Log::ERR);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function run_looper()
|
|
|
+ {
|
|
|
+ Log::record(__FUNCTION__,Log::DEBUG);
|
|
|
+ DFAFilter::instance();
|
|
|
+ area_helper::instance();
|
|
|
+ set_error_handler([$this, 'handle_error']);
|
|
|
+
|
|
|
+ Log::record('Waiting......',Log::DEBUG);
|
|
|
+ while(($ret = fcgi_accept()) >= 0)
|
|
|
+ {
|
|
|
+ $start = microtime(true);
|
|
|
+
|
|
|
+ ob_start();
|
|
|
+ $this->clear_global();
|
|
|
+ performance_helper::clear();
|
|
|
+ http_header::instance()->start();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Log::start_sql_log();
|
|
|
+ init_request();
|
|
|
+ init_cookie($_SERVER['HTTP_COOKIE']);
|
|
|
+ $file = request_helper::script_file();
|
|
|
+
|
|
|
+ if(file_exists($file))
|
|
|
+ {
|
|
|
+ if(defined('CROSS_DOAMIN') && CROSS_DOAMIN == true) {
|
|
|
+ $host = 'http://localhost:3333';
|
|
|
+ fcgi_header("Content-Type: text/html; charset=UTF-8");
|
|
|
+ fcgi_header("Access-Control-Allow-Credentials: true");
|
|
|
+ fcgi_header("Access-Control-Allow-Origin: {$host}");
|
|
|
+ fcgi_header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,PATCH');
|
|
|
+ }
|
|
|
+
|
|
|
+ if(self::is_exclude($file)) {
|
|
|
+ Log::record("Call {$file}",Log::DEBUG);
|
|
|
+ include $file;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(!isset($_GET['act'])) {
|
|
|
+ $_GET['act'] = 'index';
|
|
|
+ }
|
|
|
+ if(!isset($_GET['op'])) {
|
|
|
+ $_GET['op'] = 'index';
|
|
|
+ }
|
|
|
+ if(!isset($_POST['act'])) {
|
|
|
+ $_POST['act'] = 'index';
|
|
|
+ }
|
|
|
+ if(!isset($_POST['op'])) {
|
|
|
+ $_POST['op'] = 'index';
|
|
|
+ }
|
|
|
+
|
|
|
+ //部分控制器不需要使用session.
|
|
|
+ $act = $_GET['act'];
|
|
|
+ if($act != 'refill') {
|
|
|
+ session::instance()->start();
|
|
|
+ Log::record("member_id=" . session_helper::memberid(),Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ Base::mobile_control();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fcgi_header("Content-Type: text/html; charset=UTF-8");
|
|
|
+ echo "no such file.";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (UnloginException $ex) {
|
|
|
+ mobileControl::outerr(errcode::ErrUnLogin,errcode::msg(errcode::ErrUnLogin),'','android');
|
|
|
+ }
|
|
|
+ catch (Exception $ex) {
|
|
|
+ mobileControl::outerr($ex->getCode(),$ex->getMessage(),'','android');
|
|
|
+ Log::record("run_looper exception catch code={$ex->getCode()} msg={$ex->getMessage()} trace={$ex->getTraceAsString()}",Log::ERR);
|
|
|
+ }
|
|
|
+ session::instance()->end();
|
|
|
+ fcgi_headers_sent();
|
|
|
+ $contents = ob_get_clean();
|
|
|
+ fcgi_echo($contents);
|
|
|
+ Log::end_sql_log();
|
|
|
+// Log::record("content={$contents}",Log::DEBUG);
|
|
|
+
|
|
|
+ //fcgi_finish();//单线程的情况下不需要调用
|
|
|
+ $msg = sprintf("request time=%.6f\r\n\r\n",microtime(true) - $start);
|
|
|
+ Log::record($msg ,Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ fcgi_fini();
|
|
|
+ Log::record('Waiting quit......',Log::DEBUG);
|
|
|
+ }
|
|
|
+}
|