RequiredCheck.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * Xunsearch PHP-SDK 运行条件检测
  5. *
  6. * @author hightman
  7. * @link http://www.xunsearch.com/
  8. * @copyright Copyright &copy; 2011 HangZhou YunSheng Network Technology Co., Ltd.
  9. * @license http://www.xunsearch.com/license/
  10. * @version $Id$
  11. */
  12. $lib_file = dirname(__FILE__) . '/../lib/XS.php';
  13. if (!file_exists($lib_file)) {
  14. $lib_file = dirname(__FILE__) . '/../lib/XS.class.php';
  15. }
  16. require_once $lib_file;
  17. require dirname(__FILE__) . '/XSUtil.class.php';
  18. // magick output charset
  19. XSUtil::parseOpt(array('c', 'charset'));
  20. $charset = XSUtil::getOpt('c', 'charset');
  21. XSUtil::setCharset($charset);
  22. // result number record
  23. $result = array(
  24. 'PHP 版本' => array(
  25. 'type' => (version_compare(PHP_VERSION, '5.2.0', '>=') ? '' : 'ERROR:') . PHP_VERSION,
  26. 'used' => 'XS(core)',
  27. 'note' => 'PHP 5.2.0 或更高版本是必须的。',
  28. ),
  29. 'SPL 扩展' => array(
  30. 'type' => extension_loaded('spl') ? 'OK' : 'ERROR',
  31. 'used' => 'XS(core)',
  32. 'note' => 'SPL 扩展用于自动加载和对象戏法',
  33. ),
  34. 'PCRE 扩展' => array(
  35. 'type' => extension_loaded('pcre') ? 'OK' : 'ERROR',
  36. 'used' => 'XSDocument, XSSearch',
  37. 'note' => '用于字符串切割、判断',
  38. ),
  39. '编码转换' => array(
  40. 'type' => check_conv(),
  41. 'used' => 'XSDocument, XSSearch',
  42. 'note' => '用于支持非 UTF-8 字符集',
  43. ),
  44. '缓存模块' => array(
  45. 'type' => check_cache(),
  46. 'used' => 'XS',
  47. 'note' => '用于缓存项目配置文件的解析结果',
  48. ),
  49. 'JSON 扩展' => array(
  50. 'type' => extension_loaded('json') ? 'OK' : 'WARNING',
  51. 'used' => 'util.Quest, util.Indexer',
  52. 'note' => '用于读取或输出 JSON 格式的数据',
  53. ),
  54. 'XML 扩展' => array(
  55. 'type' => extension_loaded('xml') ? 'OK' : 'WARNING',
  56. 'used' => 'util.Indexer',
  57. 'note' => '用于读取导入 XML 格式的数据',
  58. ),
  59. 'MySQL 扩展' => array(
  60. 'type' => check_mysql(),
  61. 'used' => 'util.Indexer',
  62. 'note' => '用于读取导入 MySQL 的数据库',
  63. ),
  64. 'SQLite 扩展' => array(
  65. 'type' => check_sqlite(),
  66. 'used' => 'util.Indexer',
  67. 'note' => '用于读取导入 SQLite 的数据库',
  68. ),
  69. );
  70. // output
  71. ?>
  72. Xunsearch PHP-SDK 运行需求检查
  73. ==============================
  74. 检查内容
  75. --------
  76. 本程序用于确认您的服务器配置是否能满足运行 Xunsearch PHP-SDK 的要求。
  77. 它将检查服务器所运行的 PHP 版本,查看是否安装了合适的PHP扩展模块,以及
  78. 确认 php.ini 文件是否正确设置。
  79. <?php
  80. out_line();
  81. out_line('项目', '结果', '用于', '备注');
  82. out_line();
  83. $num_ok = $num_warning = $num_error = 0;
  84. foreach ($result as $key => $val) {
  85. if (substr($val['type'], 0, 7) == 'WARNING')
  86. $num_warning++;
  87. elseif (substr($val['type'], 0, 5) == 'ERROR')
  88. $num_error++;
  89. else
  90. $num_ok++;
  91. out_line($key, $val['type'], $val['used'], $val['note']);
  92. }
  93. out_line();
  94. ?>
  95. 检查结果
  96. --------
  97. 共计 <?php echo $num_ok; ?> 项通过,<?php echo $num_warning; ?> 项警告,<?php echo $num_error; ?> 项错误。
  98. <?php if ($num_error > 0): ?>
  99. 您的服务器配置不符合 Xunsearch/PHP-SDK 的最低要求。
  100. 请仔细查看上面表格中结果为 ERROR 的项目,并针对性的做出修改和调整。
  101. <?php else: ?>
  102. 您的服务器配置符合 Xunsearch/PHP-SDK 的最低要求。
  103. <?php if ($num_warning > 0): ?>
  104. 如果您需要使用特定的功能,请关注上述的 WARNING 项。
  105. <?php endif; ?>
  106. <?php endif; ?>
  107. <?php
  108. // check conv
  109. function check_conv()
  110. {
  111. $rec = array();
  112. if (function_exists('mb_convert_encoding')) {
  113. $rec[] = 'mbstring';
  114. }
  115. if (function_exists('iconv')) {
  116. $rec[] = 'iconv';
  117. }
  118. if (count($rec) === 0) {
  119. return 'WARNING';
  120. }
  121. return current($rec);
  122. }
  123. // check cache
  124. function check_cache()
  125. {
  126. $rec = array();
  127. if (function_exists('apc_fetch')) {
  128. $rec[] = 'apc';
  129. }
  130. if (function_exists('xcache_get')) {
  131. $rec[] = 'xcache';
  132. }
  133. if (function_exists('eaccelerator_get')) {
  134. $rec[] = 'eAccelerator';
  135. }
  136. if (count($rec) === 0) {
  137. return 'WARNING';
  138. }
  139. return current($rec);
  140. }
  141. // check mysql
  142. function check_mysql()
  143. {
  144. $rec = array();
  145. if (function_exists('mysql_connect')) {
  146. $rec[] = 'mysql';
  147. }
  148. if (class_exists('mysqli')) {
  149. $rec[] = 'mysqli';
  150. }
  151. if (extension_loaded('pdo_mysql')) {
  152. $rec[] = 'PDO_MySQL';
  153. }
  154. if (count($rec) === 0) {
  155. return 'WARNING';
  156. }
  157. return current($rec);
  158. }
  159. // check sqlite
  160. function check_sqlite()
  161. {
  162. $rec = array();
  163. if (function_exists('sqlite_open')) {
  164. $rec[] = 'sqlite';
  165. }
  166. if (class_exists('sqlite3')) {
  167. $rec[] = 'sqlite3';
  168. }
  169. if (extension_loaded('pdo_sqlite')) {
  170. $rec[] = 'PDO_SQLite';
  171. }
  172. if (count($rec) === 0) {
  173. return 'WARNING';
  174. }
  175. return current($rec);
  176. }
  177. // output line
  178. function out_line()
  179. {
  180. $args = func_get_args();
  181. if (count($args) == 4) {
  182. printf("| %s | %s | %s | %s |\n", XSUtil::fixWidth($args[0], 10), XSUtil::fixWidth($args[1], 10),
  183. XSUtil::fixWidth($args[2], 24), XSUtil::fixWidth($args[3], 30));
  184. } else {
  185. printf("+-%s-+-%s-+-%s-+-%s-+\n", XSUtil::fixWidth('', 10, '-'), XSUtil::fixWidth('', 10, '-'),
  186. XSUtil::fixWidth('', 24, '-'), XSUtil::fixWidth('', 30, '-'));
  187. }
  188. }