fcgi_run.php 2.1 KB

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