Start.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\utils;
  12. use think\App;
  13. /**
  14. * Start输出类
  15. * Class Json
  16. * @package crmeb\utils
  17. */
  18. class Start
  19. {
  20. protected $context = '';
  21. const LINE = '------------------------------------------------'.PHP_EOL;
  22. public function show()
  23. {
  24. $this->opCacheClear();
  25. $this->context = $this->logo();
  26. $this->context .= self::LINE;
  27. $this->displayItem('php version', phpversion());
  28. $this->displayItem('swoole version', phpversion('swoole'));
  29. $this->displayItem('swoole_loader version', phpversion('swoole_loader'));
  30. $this->displayItem('thinkphp version', App::VERSION);
  31. $this->displayItem('crmeb version', get_crmeb_version());
  32. //http配置
  33. $httpConf = \config("swoole.server");
  34. $this->displayItem('http host', $httpConf["host"]);
  35. $this->displayItem('http port', $httpConf["port"]);
  36. $this->displayItem('http worker_num', $httpConf['options']["worker_num"]);
  37. //websocket配置
  38. $this->displayItem('websocket enable', \config("swoole.websocket.enable"));
  39. //rpc配置
  40. $rpcConf = \config("swoole.rpc.server");
  41. $this->displayItem('rpc enable', $rpcConf["enable"]);
  42. if ($rpcConf["enable"]) {
  43. $this->displayItem('rpc host', $rpcConf["host"]);
  44. $this->displayItem('rpc port', $rpcConf["port"]);
  45. $this->displayItem('rpc worker_num', $rpcConf["worker_num"]);
  46. }
  47. //队列配置
  48. $this->displayItem('queue enable', \config("swoole.queue.enable"));
  49. //热更新配置
  50. $this->displayItem('hot_update enable', (bool)\config("swoole.hot_update.enable"));
  51. //debug配置
  52. $this->displayItem('app_debug enable', (bool)env("APP_DEBUG"));
  53. $this->displayItem('time', date('Y-m-d H:i:s'));
  54. $this->displayItem('可在命令行执行,查看更多 ','php think cm_cli');
  55. //打印信息
  56. echo $this->context;
  57. }
  58. private function logo()
  59. {
  60. return <<<LOGO
  61. ██████ ███████ ████ ████ ████████ ██████ ████ ████ ████████ ███████
  62. ██░░░░██░██░░░░██ ░██░██ ██░██░██░░░░░ ░█░░░░██ ░██░██ ██░██░██░░░░░ ░██░░░░██
  63. ██ ░░ ░██ ░██ ░██░░██ ██ ░██░██ ░█ ░██ ░██░░██ ██ ░██░██ ░██ ░██
  64. ░██ ░███████ ░██ ░░███ ░██░███████ ░██████ █████░██ ░░███ ░██░███████ ░███████
  65. ░██ ░██░░░██ ░██ ░░█ ░██░██░░░░ ░█░░░░ ██░░░░░ ░██ ░░█ ░██░██░░░░ ░██░░░██
  66. ░░██ ██░██ ░░██ ░██ ░ ░██░██ ░█ ░██ ░██ ░ ░██░██ ░██ ░░██
  67. ░░██████ ░██ ░░██░██ ░██░████████░███████ ░██ ░██░████████░██ ░░██
  68. ░░░░░░ ░░ ░░ ░░ ░░ ░░░░░░░░ ░░░░░░░ ░░ ░░ ░░░░░░░░ ░░ ░░
  69. LOGO;
  70. }
  71. private function displayItem($name, $value)
  72. {
  73. if ($value === true) {
  74. $value = 'true';
  75. }
  76. elseif ($value === false) {
  77. $value = 'false';
  78. }
  79. elseif ($value === null) {
  80. $value = 'null';
  81. }
  82. $this->context .= "\e[32m" . str_pad($name, 25, ' ', STR_PAD_RIGHT) .'| '. "\e[34m" . $value . "\e[0m \n";
  83. $this->context .= self::LINE;
  84. }
  85. private function opCacheClear()
  86. {
  87. if (function_exists('apc_clear_cache')) {
  88. apc_clear_cache();
  89. }
  90. if (function_exists('opcache_reset')) {
  91. opcache_reset();
  92. }
  93. }
  94. }