fcgi_server.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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','test.php');
  21. $name = basename($file);
  22. return in_array($name,$exfiles);
  23. }
  24. public function run_looper()
  25. {
  26. require_once(BASE_ROOT_PATH.'/mobile/index.php');
  27. Base::mobile_init();
  28. while(($ret = fcgi_accept()) >= 0)
  29. {
  30. ob_start();
  31. http_header::instance()->start();
  32. try
  33. {
  34. Log::start_sql_log();
  35. init_request();
  36. init_cookie($_SERVER['HTTP_COOKIE']);
  37. session::instance()->start();
  38. Log::record("req_uri = " . request_helper::req_uri(),Log::DEBUG);
  39. $file = request_helper::script_file();
  40. if(file_exists($file))
  41. {
  42. if(self::is_exclude($file)) {
  43. include $file;
  44. } else {
  45. fcgi_header("Content-Type: text/html; charset=UTF-8");
  46. Base::mobile_control();
  47. }
  48. }
  49. else
  50. {
  51. fcgi_header("Content-Type: text/html; charset=UTF-8");
  52. echo "no such file.";
  53. }
  54. }
  55. catch (TypeException $ex) {
  56. mobileControl::outerr($ex->getCode(),$ex->getMessage());
  57. }
  58. catch (Exception $ex) {
  59. mobileControl::outerr($ex->getCode(),$ex->getMessage());
  60. }
  61. fcgi_headers_sent();
  62. $contents = ob_get_clean();
  63. fcgi_echo($contents);
  64. session::instance()->end();
  65. fcgi_finish();
  66. }
  67. fcgi_fini();
  68. }
  69. }