RequiredCheck.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. {
  82. if (substr($val['type'], 0, 7) == 'WARNING')
  83. $num_warning++;
  84. else if (substr($val['type'], 0, 5) == 'ERROR')
  85. $num_error++;
  86. else
  87. $num_ok++;
  88. out_line($key, $val['type'], $val['used'], $val['note']);
  89. }
  90. out_line();
  91. ?>
  92. 检查结果
  93. --------
  94. 共计 <?php echo $num_ok; ?> 项通过,<?php echo $num_warning; ?> 项警告,<?php echo $num_error; ?> 项错误。
  95. <?php if ($num_error > 0): ?>
  96. 您的服务器配置不符合 Xunsearch/PHP-SDK 的最低要求。
  97. 请仔细查看上面表格中结果为 ERROR 的项目,并针对性的做出修改和调整。
  98. <?php else: ?>
  99. 您的服务器配置符合 Xunsearch/PHP-SDK 的最低要求。
  100. <?php if ($num_warning > 0): ?>
  101. 如果您需要使用特定的功能,请关注上述的 WARNING 项。
  102. <?php endif; ?>
  103. <?php endif; ?>
  104. <?php
  105. // check conv
  106. function check_conv()
  107. {
  108. $rec = array();
  109. if (function_exists('mb_convert_encoding'))
  110. $rec[] = 'mbstring';
  111. if (function_exists('iconv'))
  112. $rec[] = 'iconv';
  113. if (count($rec) === 0)
  114. return 'WARNING';
  115. return current($rec);
  116. }
  117. // check cache
  118. function check_cache()
  119. {
  120. $rec = array();
  121. if (function_exists('apc_fetch'))
  122. $rec[] = 'apc';
  123. if (function_exists('xcache_get'))
  124. $rec[] = 'xcache';
  125. if (function_exists('eaccelerator_get'))
  126. $rec[] = 'eAccelerator';
  127. if (count($rec) === 0)
  128. return 'WARNING';
  129. return current($rec);
  130. }
  131. // check mysql
  132. function check_mysql()
  133. {
  134. $rec = array();
  135. if (function_exists('mysql_connect'))
  136. $rec[] = 'mysql';
  137. if (class_exists('mysqli'))
  138. $rec[] = 'mysqli';
  139. if (extension_loaded('pdo_mysql'))
  140. $rec[] = 'PDO_MySQL';
  141. if (count($rec) === 0)
  142. return 'WARNING';
  143. return current($rec);
  144. }
  145. // check sqlite
  146. function check_sqlite()
  147. {
  148. $rec = array();
  149. if (function_exists('sqlite_open'))
  150. $rec[] = 'sqlite';
  151. if (class_exists('sqlite3'))
  152. $rec[] = 'sqlite3';
  153. if (extension_loaded('pdo_sqlite'))
  154. $rec[] = 'PDO_SQLite';
  155. if (count($rec) === 0)
  156. return 'WARNING';
  157. return current($rec);
  158. }
  159. // output line
  160. function out_line()
  161. {
  162. $args = func_get_args();
  163. if (count($args) == 4)
  164. {
  165. printf("| %s | %s | %s | %s |\n",
  166. XSUtil::fixWidth($args[0], 10),
  167. XSUtil::fixWidth($args[1], 10),
  168. XSUtil::fixWidth($args[2], 24),
  169. XSUtil::fixWidth($args[3], 30));
  170. }
  171. else
  172. {
  173. printf("+-%s-+-%s-+-%s-+-%s-+\n",
  174. XSUtil::fixWidth('', 10, '-'),
  175. XSUtil::fixWidth('', 10, '-'),
  176. XSUtil::fixWidth('', 24, '-'),
  177. XSUtil::fixWidth('', 30, '-'));
  178. }
  179. }