RequiredCheck.php 4.8 KB

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