index.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. use lwmf\base\Config;
  3. //定义app id
  4. define('LWM_APP_ID', "www");
  5. //定义项目根目录
  6. define('LWM_PROJECT_PATH', dirname(dirname(__FILE__)));
  7. //YII框架路径
  8. define('YII_PATH', dirname(LWM_PROJECT_PATH) . '/yii/framework');
  9. // remove the following lines when in production mode
  10. defined('YII_DEBUG') or define('YII_DEBUG', false);
  11. // specify how many levels of call stack should be shown in each log message
  12. defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',5);
  13. //开启性能分析 - 线上关闭
  14. $isOpenTideways = false;
  15. if (function_exists('tideways_enable')) {
  16. $isOpenTideways = true;
  17. tideways_enable(TIDEWAYS_FLAGS_NO_SPANS);
  18. }
  19. require_once LWM_PROJECT_PATH .'/system/commons/Loader.php';
  20. // change the following paths if necessary
  21. //加载扩展后的YII框架
  22. require LWM_PROJECT_PATH . '/lwmf/Yii.php';
  23. //初始化静态资源常量
  24. define('LWM_ASSETS_URL', Config::getInstance()->get('assetsUrl'));
  25. define("LWM_API_KEY", "C9B90DD1E5A8A4677CFD6C3A0B73B4F2");
  26. //初始化当前系统环境
  27. define('LWM_ENV', Config::getInstance()->get('env'));
  28. //获取默认配置
  29. $config = Config::getInstance()->get('', 'main');
  30. $app = Yii::createWebApplication($config);
  31. //记录性能分析日志 - 线上关闭
  32. if ($isOpenTideways) {
  33. $app->attachEventHandler('onEndRequest', function () {
  34. $data = tideways_disable();
  35. $logPath = "/alidata/log/tideways";
  36. if (file_exists($logPath)) {
  37. $app = Yii::app();
  38. $logName = $app->request->getPathInfo();
  39. if ($app instanceof \lwmf\base\WebApplication) {
  40. $logName = $app->getRoute();
  41. }
  42. if (empty($logName)) {
  43. $logName = '/';
  44. }
  45. $logName = LWM_APP_ID . "_" . $logName;
  46. $logName = $logPath . "/" . str_replace('/', '_', $logName) . "_" . uniqid() .".lewaimai.xhprof";
  47. file_put_contents(
  48. $logName,
  49. serialize($data)
  50. );
  51. }
  52. });
  53. }
  54. $app->run();