Check.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace easyTask;
  3. /**
  4. * Class Check
  5. * @package easyTask
  6. */
  7. class Check
  8. {
  9. /**
  10. * 待检查扩展列表
  11. * @var array
  12. */
  13. private static $waitExtends = [
  14. //Win
  15. '1' => [
  16. 'json',
  17. 'curl',
  18. 'com_dotnet',
  19. 'mbstring',
  20. ],
  21. //Linux
  22. '2' => [
  23. 'json',
  24. 'curl',
  25. 'pcntl',
  26. 'posix',
  27. 'mbstring',
  28. ]
  29. ];
  30. /**
  31. * 待检查函数列表
  32. * @var array
  33. */
  34. private static $waitFunctions = [
  35. //Win
  36. '1' => [
  37. 'umask',
  38. 'sleep',
  39. 'usleep',
  40. 'ob_start',
  41. 'ob_end_clean',
  42. 'ob_get_contents',
  43. ],
  44. //Linux
  45. '2' => [
  46. 'umask',
  47. 'chdir',
  48. 'sleep',
  49. 'usleep',
  50. 'ob_start',
  51. 'ob_end_clean',
  52. 'ob_get_contents',
  53. 'pcntl_fork',
  54. 'posix_setsid',
  55. 'posix_getpid',
  56. 'posix_getppid',
  57. 'pcntl_wait',
  58. 'posix_kill',
  59. 'pcntl_signal',
  60. 'pcntl_alarm',
  61. 'pcntl_waitpid',
  62. 'pcntl_signal_dispatch',
  63. ]
  64. ];
  65. /**
  66. * 解析运行环境
  67. * @param int $currentOs
  68. */
  69. public static function analysis($currentOs)
  70. {
  71. //检查扩展
  72. $waitExtends = static::$waitExtends[$currentOs];
  73. foreach ($waitExtends as $extend)
  74. {
  75. if (!extension_loaded($extend))
  76. {
  77. Helper::showSysError("php_{$extend}.(dll/so) is not load,please check php.ini file");
  78. }
  79. }
  80. //检查函数
  81. $waitFunctions = static::$waitFunctions[$currentOs];
  82. foreach ($waitFunctions as $func)
  83. {
  84. if (!function_exists($func))
  85. {
  86. Helper::showSysError("function $func may be disabled,please check disable_functions in php.ini");
  87. }
  88. }
  89. }
  90. }