check-environment.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. include_once './common.php';
  3. define('TEST_PASS', 'PASS');
  4. define('TEST_FAIL', 'FAIL');
  5. define('MIN_PHP_VERSION', '5.2.11');
  6. define('MIN_ZF_VERSION', '1.10.0beta');
  7. define('SOCKET_TIMEOUT', 5); // seconds
  8. $failed = false;
  9. $counter = 1;
  10. // -----------------------------------------------------------------------------
  11. ini_set('default_socket_timeout', SOCKET_TIMEOUT);
  12. printf('%sZend_Service_LiveDocx Environment Checker%s%s', PHP_EOL, PHP_EOL, PHP_EOL);
  13. // -----------------------------------------------------------------------------
  14. printLine($counter, sprintf('Checking OS (%s)', PHP_OS), TEST_PASS);
  15. $counter ++;
  16. // -----------------------------------------------------------------------------
  17. if ('cli' === strtolower(PHP_SAPI)) {
  18. $result = TEST_PASS;
  19. } else {
  20. $result = TEST_FAIL;
  21. $failed = true;
  22. }
  23. printLine($counter, sprintf('Checking SAPI (%s)', PHP_SAPI), $result);
  24. $counter ++;
  25. // -----------------------------------------------------------------------------
  26. if (1 === version_compare(PHP_VERSION, MIN_PHP_VERSION)) {
  27. $result = TEST_PASS;
  28. } else {
  29. $result = TEST_FAIL;
  30. $failed = true;
  31. }
  32. printLine($counter, sprintf('Checking PHP version (%s)', PHP_VERSION), $result);
  33. $counter ++;
  34. // -----------------------------------------------------------------------------
  35. printLine($counter, sprintf('Checking memory limit (%s)', ini_get('memory_limit')), TEST_PASS);
  36. $counter ++;
  37. // -----------------------------------------------------------------------------
  38. if (in_array('http', stream_get_wrappers())) {
  39. $result = TEST_PASS;
  40. } else {
  41. $result = TEST_FAIL;
  42. $failed = true;
  43. }
  44. printLine($counter, 'Checking HTTP stream wrapper', $result);
  45. $counter ++;
  46. // -----------------------------------------------------------------------------
  47. if (in_array('https', stream_get_wrappers())) {
  48. $result = TEST_PASS;
  49. } else {
  50. $result = TEST_FAIL;
  51. $failed = true;
  52. }
  53. printLine($counter, 'Checking HTTPS stream wrapper', $result);
  54. $counter ++;
  55. // -----------------------------------------------------------------------------
  56. if (true === method_exists('Zend_Debug', 'dump')) {
  57. $result = TEST_PASS;
  58. } else {
  59. $result = TEST_FAIL;
  60. $failed = true;
  61. }
  62. printLine($counter, 'Checking Zend Framework path', $result);
  63. $counter ++;
  64. // -----------------------------------------------------------------------------
  65. if (1 === Zend_Version::compareVersion(PHP_VERSION, MIN_PHP_VERSION)) {
  66. $result = TEST_PASS;
  67. } else {
  68. $result = TEST_FAIL;
  69. $failed = true;
  70. }
  71. printLine($counter, sprintf('Checking Zend Framework version (%s)', Zend_Version::VERSION), $result);
  72. $counter ++;
  73. // -----------------------------------------------------------------------------
  74. if (extension_loaded('soap')) {
  75. $result = TEST_PASS;
  76. } else {
  77. $result = TEST_FAIL;
  78. $failed = true;
  79. }
  80. printLine($counter, 'Checking SOAP extension', $result);
  81. $counter ++;
  82. // -----------------------------------------------------------------------------
  83. if (extension_loaded('dom')) {
  84. $result = TEST_PASS;
  85. } else {
  86. $result = TEST_FAIL;
  87. $failed = true;
  88. }
  89. printLine($counter, 'Checking DOM extension', $result);
  90. $counter ++;
  91. // -----------------------------------------------------------------------------
  92. if (extension_loaded('simplexml')) {
  93. $result = TEST_PASS;
  94. } else {
  95. $result = TEST_FAIL;
  96. $failed = true;
  97. }
  98. printLine($counter, 'Checking SimpleXML extension', $result);
  99. $counter ++;
  100. // -----------------------------------------------------------------------------
  101. if (extension_loaded('libxml')) {
  102. $result = TEST_PASS;
  103. } else {
  104. $result = TEST_FAIL;
  105. $failed = true;
  106. }
  107. printLine($counter, 'Checking libXML extension', $result);
  108. $counter ++;
  109. // -----------------------------------------------------------------------------
  110. $geoData = @file_get_contents('http://api.ipinfodb.com/v2/ip_query.php?key=332bde528d94fe578455e18ad225a01cba8dd359ee915ee46b70ca5e67137252');
  111. $keys = array (
  112. 'Ip' => 'IP address',
  113. 'City' => 'city',
  114. 'RegionName' => 'region',
  115. 'CountryName' => 'country'
  116. );
  117. if (false !== $geoData) {
  118. $simplexml = new SimpleXMLElement($geoData);
  119. foreach ($keys as $key => $value) {
  120. printLine($counter, sprintf('Checking your %s (%s)', $keys[$key], $simplexml->$key), TEST_PASS);
  121. $counter ++;
  122. }
  123. } else {
  124. printLine($counter, 'Checking your geo data', TEST_FAIL);
  125. $failed = true;
  126. }
  127. // -----------------------------------------------------------------------------
  128. $microtime = microtime(true);
  129. if (false !== file_get_contents(Zend_Service_LiveDocx_MailMerge::WSDL)) {
  130. $duration = microtime(true) - $microtime;
  131. $result = TEST_PASS;
  132. } else {
  133. $duration = -1;
  134. $result = TEST_FAIL;
  135. $failed = true;
  136. }
  137. printLine($counter, sprintf('Checking backend WSDL (%01.2fs)', $duration), $result);
  138. $counter ++;
  139. // -----------------------------------------------------------------------------
  140. if (defined('DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME') &&
  141. defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD')) {
  142. $result = TEST_PASS;
  143. } else {
  144. $result = TEST_FAIL;
  145. $failed = true;
  146. }
  147. printLine($counter, 'Checking backend credentials are defined', $result);
  148. $counter ++;
  149. // -----------------------------------------------------------------------------
  150. $errorMessage = null;
  151. try {
  152. $microtime = microtime(true);
  153. $mailMerge = new Zend_Service_LiveDocx_MailMerge(
  154. array (
  155. 'username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME,
  156. 'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD
  157. )
  158. );
  159. $mailMerge->logIn();
  160. $duration = microtime(true) - $microtime;
  161. } catch (Zend_Service_LiveDocx_Exception $e) {
  162. $duration = -1;
  163. $errorMessage = $e->getMessage();
  164. }
  165. if (is_null($errorMessage)) {
  166. $result = TEST_PASS;
  167. } else {
  168. $result = TEST_FAIL;
  169. $failed = true;
  170. }
  171. printLine($counter, sprintf('Logging into backend service (%01.2fs)', $duration), $result);
  172. $counter ++;
  173. // -----------------------------------------------------------------------------
  174. if (true === $failed) {
  175. $message = 'One or more tests failed. The web server environment, in which this script is running, does not meet the requirements for Zend_Service_LiveDocx_*.';
  176. } else {
  177. $message = 'Congratulations! All tests passed. The server environment, in which this script is running, is suitable for Zend_Service_LiveDocx_*.';
  178. }
  179. print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(PHP_EOL . $message . PHP_EOL . PHP_EOL));
  180. // -----------------------------------------------------------------------------
  181. /**
  182. * Print result line
  183. *
  184. * @param int $counter
  185. * @param string $testString
  186. * @param mixed $testResult
  187. * @return void
  188. */
  189. function printLine($counter, $testString, $testResult)
  190. {
  191. $lineLength = Demos_Zend_Service_LiveDocx_Helper::LINE_LENGTH;
  192. // counter result
  193. $padding = $lineLength - (4 + strlen(TEST_PASS));
  194. $counter = sprintf('%2s: ', $counter);
  195. $testString = str_pad($testString, $padding, '.', STR_PAD_RIGHT);
  196. printf('%s%s%s%s', $counter, $testString, $testResult, PHP_EOL);
  197. }
  198. // -----------------------------------------------------------------------------