fcgi_run.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
  3. define('MOBILE_SERVER',true);
  4. require_once (BASE_ROOT_PATH . '/fooder.php');
  5. require_once (BASE_ROOT_PATH . '/helper/http_header.php');
  6. require_once (BASE_ROOT_PATH . '/helper/session.php');
  7. require_once (BASE_ROOT_PATH . '/helper/func.php');
  8. require_once (BASE_ROOT_PATH . '/helper/exceptionex.php');
  9. require_once (BASE_ROOT_PATH . '/helper/fcgi_server.php');
  10. function pays_execute($file)
  11. {
  12. static $exfiles = array('wxnotify.php','alipay_notify_url.php','dispatch_notify.php','test.php');
  13. $name = basename($file);
  14. return in_array($name,$exfiles);
  15. }
  16. function run_fcgi()
  17. {
  18. require_once(BASE_ROOT_PATH.'/mobile/index.php');
  19. Base::mobile_init();
  20. while(($ret = fcgi_accept()) >= 0)
  21. {
  22. ob_start();
  23. $timestamp = time();
  24. $startime = microtime(true);
  25. define('StartTime',$startime);
  26. define('TIMESTAMP',$timestamp);
  27. http_header::instance()->start();
  28. try
  29. {
  30. init_request();
  31. init_cookie($_SERVER['HTTP_COOKIE']);
  32. session::instance()->start();
  33. Log::record(request_helper::req_uri(),Log::DEBUG);
  34. $file = request_helper::script_file();
  35. if(file_exists($file))
  36. {
  37. if(pays_execute($file)) {
  38. include $file;
  39. } else {
  40. fcgi_header("Content-Type: text/html; charset=UTF-8");
  41. Base::mobile_control();
  42. }
  43. }
  44. else
  45. {
  46. fcgi_header("Content-Type: text/html; charset=UTF-8");
  47. echo "no such file.";
  48. }
  49. }
  50. catch (TypeException $ex) {
  51. joutput_error($ex->getCode(),$ex->getMessage());
  52. }
  53. catch (Exception $ex) {
  54. joutput_error($ex->getCode(),$ex->getMessage().'@@@@@'.$ex->getTraceAsString());
  55. }
  56. fcgi_headers_sent();
  57. $contents = ob_get_clean();
  58. fcgi_echo($contents);
  59. Log::record("use time = " . ($startime - microtime(true)),Log::DEBUG);
  60. session::instance()->end();
  61. fcgi_finish();
  62. }
  63. fcgi_fini();
  64. }
  65. function run_srver()
  66. {
  67. fcgi_server::instance()->run_looper();
  68. }
  69. run_srver();
  70. ?>