fcgi_server.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/3/10
  6. * Time: 下午9:08
  7. */
  8. class fcgi_server
  9. {
  10. static private $stInstance = NULL;
  11. static public function instance()
  12. {
  13. if(self::$stInstance == NULL) {
  14. self::$stInstance = new fcgi_server();
  15. }
  16. return self::$stInstance;
  17. }
  18. private function is_exclude($file)
  19. {
  20. static $exfiles = array('wxnotify.php','alipay_notify_url.php','dispatch_notify.php','kdniao_notify.php','test.php','cmbpay.php');
  21. $name = basename($file);
  22. return in_array($name,$exfiles);
  23. }
  24. private function parase_requri()
  25. {
  26. $method = strtolower(request_helper::method());
  27. if($method == 'get') {
  28. return;
  29. }
  30. $file = request_helper::req_uri();
  31. $ops = explode("?",$file);
  32. if(count($ops) == 2)
  33. {
  34. $squery = $ops[1];
  35. $params = preg_split('/&|=/', $squery);
  36. for ($i = 0; $i < count($params); ++$i) {
  37. $key = $params[$i];
  38. $val = $params[++$i];
  39. $_GET[$key] = $val;
  40. $_POST[$key] = $val;
  41. }
  42. }
  43. }
  44. public function run_looper()
  45. {
  46. //载入敏感词词库
  47. DFAFilter::instance();
  48. require_once(BASE_ROOT_PATH.'/mobile/index.php');
  49. Base::mobile_init();
  50. while(($ret = fcgi_accept()) >= 0)
  51. {
  52. ob_start();
  53. performance_helper::clear();
  54. http_header::instance()->start();
  55. try
  56. {
  57. Log::start_sql_log();
  58. Log::record("req_uri = " . request_helper::req_uri(),Log::DEBUG);
  59. $this->parase_requri();
  60. init_request();
  61. init_cookie($_SERVER['HTTP_COOKIE']);
  62. session::instance()->start();
  63. $file = request_helper::script_file();
  64. if(file_exists($file))
  65. {
  66. if(self::is_exclude($file)) {
  67. include $file;
  68. }
  69. else
  70. {
  71. fcgi_header("Content-Type: text/html; charset=UTF-8");
  72. if(!array_key_exists('act',$_GET)) {
  73. $_GET['act'] = 'index';
  74. }
  75. if(!array_key_exists('op',$_GET)) {
  76. $_GET['op'] = 'index';
  77. }
  78. if(!array_key_exists('act',$_POST)) {
  79. $_POST['act'] = 'index';
  80. }
  81. if(!array_key_exists('op',$_POST)) {
  82. $_POST['op'] = 'index';
  83. }
  84. Base::mobile_control();
  85. }
  86. }
  87. else
  88. {
  89. fcgi_header("Content-Type: text/html; charset=UTF-8");
  90. echo "no such file.";
  91. }
  92. }
  93. catch (Exception $ex) {
  94. mobileControl::outerr($ex->getCode(),$ex->getMessage());
  95. }
  96. fcgi_headers_sent();
  97. $contents = ob_get_clean();
  98. fcgi_echo($contents);
  99. //Log::record("return msg={$contents}",Log::DEBUG);
  100. session::instance()->end();
  101. fcgi_finish();
  102. }
  103. fcgi_fini();
  104. }
  105. }