fcgi_run.php 2.1 KB

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