Science.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\admin\controller\setting;
  13. use app\admin\controller\Controller;
  14. use app\common\library\helper;
  15. /**
  16. * 环境检测
  17. * Class Science
  18. * @package app\admin\controller\setting
  19. */
  20. class Science extends Controller
  21. {
  22. /**
  23. * 环境检测
  24. * @return array
  25. */
  26. public function info(): array
  27. {
  28. return $this->renderSuccess([
  29. 'scienceInfo' => [
  30. 'server' => $this->server(), // 服务器信息
  31. 'phpinfo' => $this->phpinfo(), // PHP环境要求
  32. 'writeable' => $this->writeable(), // 目录权限监测
  33. ]
  34. ]);
  35. }
  36. /**
  37. * 服务器信息
  38. * @return array
  39. */
  40. private function server()
  41. {
  42. return [
  43. [
  44. 'name' => '服务器操作系统',
  45. 'key' => 'system',
  46. 'value' => PHP_OS,
  47. 'status' => PHP_SHLIB_SUFFIX === 'dll' ? 'warning' : 'normal',
  48. 'remark' => '建议使用 Linux 系统以提升程序性能'
  49. ],
  50. [
  51. 'name' => 'Web服务器环境',
  52. 'key' => 'webserver',
  53. 'value' => $this->request->server('SERVER_SOFTWARE'),
  54. 'status' => PHP_SAPI === 'isapi' ? 'warning' : 'normal',
  55. 'remark' => '建议使用 Apache 或 Nginx 以提升程序性能'
  56. ],
  57. [
  58. 'name' => 'PHP版本',
  59. 'key' => 'php',
  60. 'value' => PHP_VERSION,
  61. 'status' => version_compare(PHP_VERSION, '7.2.0') === -1 ? 'danger' : 'normal',
  62. 'remark' => 'PHP版本必须为 7.2.0 以上'
  63. ],
  64. [
  65. 'name' => 'PHP运行位数',
  66. 'key' => 'system',
  67. 'value' => (PHP_INT_SIZE === 4 ? '32' : '64') . '位',
  68. 'status' => PHP_INT_SIZE === 4 ? 'warning' : 'normal',
  69. 'remark' => '建议使用 64位 PHP以提升程序性能'
  70. ],
  71. // [
  72. // 'name' => '文件上传功能',
  73. // 'key' => 'file_uploads',
  74. // 'value' => !ini_get('file_uploads') ? '关闭' : '开启',
  75. // 'status' => !ini_get('file_uploads') ? 'danger' : 'normal',
  76. // 'remark' => '文件上传必须开启 file_uploads'
  77. // ],
  78. [
  79. 'name' => '文件上传最大值',
  80. 'key' => 'upload_max_filesize',
  81. 'value' => ini_get('upload_max_filesize'),
  82. 'status' => $this->compareBytes(ini_get('upload_max_filesize'), '10m') ? 'danger' : 'normal',
  83. 'remark' => '不能小于10MB;请修改php.ini中upload_max_filesize'
  84. ],
  85. [
  86. 'name' => 'POST数据最大值',
  87. 'key' => 'post_max_size',
  88. 'value' => ini_get('post_max_size'),
  89. 'status' => $this->compareBytes(ini_get('post_max_size'), '12m') ? 'danger' : 'normal',
  90. 'remark' => '不能小于12MB;请修改php.ini中post_max_size'
  91. ],
  92. [
  93. 'name' => '程序运行目录',
  94. 'key' => 'web_path',
  95. 'value' => str_replace('\\', '/', web_path()),
  96. 'status' => 'normal',
  97. 'remark' => ''
  98. ],
  99. ];
  100. }
  101. /**
  102. * PHP环境要求
  103. * get_loaded_extensions()
  104. * @return array
  105. */
  106. private function phpinfo()
  107. {
  108. return [
  109. [
  110. 'name' => 'PHP版本',
  111. 'key' => 'php_version',
  112. 'value' => '7.2.0及以上',
  113. 'status' => version_compare(PHP_VERSION, '7.2.0') === -1 ? 'danger' : 'normal',
  114. 'remark' => 'PHP版本必须为 7.2.0及以上'
  115. ],
  116. [
  117. 'name' => 'CURL',
  118. 'key' => 'curl',
  119. 'value' => '支持',
  120. 'status' => extension_loaded('curl') && function_exists('curl_init') ? 'normal' : 'danger',
  121. 'remark' => '您的PHP环境不支持CURL, 系统无法正常运行'
  122. ],
  123. [
  124. 'name' => 'OpenSSL',
  125. 'key' => 'openssl',
  126. 'value' => '支持',
  127. 'status' => extension_loaded('openssl') ? 'normal' : 'danger',
  128. 'remark' => '没有启用OpenSSL, 将无法访问微信平台的接口'
  129. ],
  130. [
  131. 'name' => 'PDO',
  132. 'key' => 'pdo',
  133. 'value' => '支持',
  134. 'status' => extension_loaded('PDO') && extension_loaded('pdo_mysql') ? 'normal' : 'danger',
  135. 'remark' => '您的PHP环境不支持PDO, 系统无法正常运行'
  136. ],
  137. [
  138. 'name' => 'GD',
  139. 'key' => 'gd',
  140. 'value' => '支持',
  141. 'status' => extension_loaded('gd') ? 'normal' : 'danger',
  142. 'remark' => '您的PHP环境不支持GD, 系统无法正常生成图片'
  143. ],
  144. [
  145. 'name' => 'BCMath',
  146. 'key' => 'bcmath',
  147. 'value' => '支持',
  148. 'status' => extension_loaded('bcmath') ? 'normal' : 'danger',
  149. 'remark' => '您的PHP环境不支持BCMath, 系统无法正常运行'
  150. ],
  151. [
  152. 'name' => 'mbstring',
  153. 'key' => 'mbstring',
  154. 'value' => '支持',
  155. 'status' => extension_loaded('mbstring') ? 'normal' : 'danger',
  156. 'remark' => '您的PHP环境不支持mbstring, 系统无法正常运行'
  157. ],
  158. [
  159. 'name' => 'SimpleXML',
  160. 'key' => 'simplexML',
  161. 'value' => '支持',
  162. 'status' => extension_loaded('SimpleXML') ? 'normal' : 'danger',
  163. 'remark' => '您的PHP环境不支持SimpleXML, 系统无法解析xml 无法使用微信支付'
  164. ],
  165. ];
  166. }
  167. /**
  168. * 目录权限监测
  169. */
  170. private function writeable(): array
  171. {
  172. $paths = [
  173. 'uploads' => realpath(web_path()) . '/uploads/',
  174. 'temp' => realpath(web_path()) . '/temp/',
  175. 'wxpay_log' => realpath(base_path()) . '/common/library/wechat/logs/',
  176. 'wxpay_cert' => realpath(base_path()) . '/common/library/wechat/cert/',
  177. ];
  178. return [
  179. [
  180. 'name' => '文件上传目录',
  181. 'key' => 'uploads',
  182. 'value' => str_replace('\\', '/', $paths['uploads']),
  183. 'status' => helper::checkWriteable($paths['uploads']) ? 'normal' : 'danger',
  184. 'remark' => '目录不可写,系统将无法正常上传文件'
  185. ],
  186. [
  187. 'name' => '临时文件目录',
  188. 'key' => 'temp',
  189. 'value' => str_replace('\\', '/', $paths['temp']),
  190. 'status' => helper::checkWriteable($paths['temp']) ? 'normal' : 'danger',
  191. 'remark' => '目录不可写,系统将无法正常写入文件'
  192. ],
  193. // [
  194. // 'name' => '微信支付日志目录',
  195. // 'key' => 'wxpay_log',
  196. // 'value' => str_replace('\\', '/', $paths['wxpay_log']),
  197. // 'status' => helper::checkWriteable($paths['wxpay_log']) ? 'normal' : 'danger',
  198. // 'remark' => '目录不可写,系统将无法正常写入文件'
  199. // ],
  200. [
  201. 'name' => '微信支付证书目录',
  202. 'key' => 'wxpay_cert',
  203. 'value' => str_replace('\\', '/', $paths['wxpay_cert']),
  204. 'status' => helper::checkWriteable($paths['wxpay_cert']) ? 'normal' : 'danger',
  205. 'remark' => '目录不可写,系统将无法正常写入文件'
  206. ],
  207. ];
  208. }
  209. /**
  210. * 比较数据大小
  211. * @param string $size1
  212. * @param string $size2
  213. * @return bool
  214. */
  215. private function compareBytes(string $size1, string $size2): bool
  216. {
  217. $size1 = helper::convertToBytes($size1);
  218. $size2 = helper::convertToBytes($size2);
  219. return $size1 < $size2;
  220. }
  221. }