Test.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * 此文件用于检测DEMO运行环境,无需修改,请在浏览器中运行检测
  4. *
  5. * 2017/11/19
  6. */
  7. echo '<style>li {font-size: 16px;} li.fail {color:red} li.success {color: green} li label{ display:inline-block; width: 15em}</style>';
  8. echo '<h1>执行环境检测</h1>';
  9. function success($title) {
  10. print_r("<li class=\"success\"><label>{$title}</label>[成功]</li>");
  11. }
  12. function fail($title, $description) {
  13. print_r("<li class=\"fail\"><label>{$title}</label>[失败] {$description}</li>");
  14. }
  15. if(preg_match("/^\d+\.\d+/", PHP_VERSION, $matches)) {
  16. $version = $matches[0];
  17. if($version >= 5.4) {
  18. success("PHP $version");
  19. } else {
  20. fail("PHP $version", "需要PHP>=5.4版本");
  21. exit(1);
  22. }
  23. }
  24. try {
  25. set_error_handler(function () { throw new Exception(); });
  26. date_default_timezone_get();
  27. restore_error_handler();
  28. } catch(Exception $e) {
  29. fail('默认时区设置', '请设置默认时区,如:date_default_timezone_set("Asia/Shanghai")');
  30. }
  31. echo '<h2>依赖扩展检测,如失败请安装相应扩展</h2>';
  32. $dependencies = array (
  33. 'json_encode' => null,
  34. 'curl_init' => null,
  35. 'hash_hmac' => null,
  36. 'simplexml_load_string' => '如果是php7.x + ubuntu环境,请确认php7.x-libxml是否安装,x为子版本号',
  37. );
  38. foreach($dependencies as $funcName => $description) {
  39. if(!function_exists($funcName)) {
  40. fail($funcName, $description || '');
  41. } else {
  42. success($funcName);
  43. }
  44. }