check-environment.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #!/usr/bin/php
  2. <?php
  3. include_once './common.php';
  4. define('TEST_PASS', 'PASS');
  5. define('TEST_FAIL', 'FAIL');
  6. define('MIN_PHP_VERSION', '5.2.4');
  7. define('MIN_ZF_VERSION', '1.8.0');
  8. define('SOCKET_TIMEOUT', 5); // seconds
  9. $failed = false;
  10. $counter = 1;
  11. // -----------------------------------------------------------------------------
  12. ini_set('default_socket_timeout', SOCKET_TIMEOUT);
  13. printf('%sZend_Service_LiveDocx Environment Checker%s%s', PHP_EOL, PHP_EOL, PHP_EOL);
  14. // -----------------------------------------------------------------------------
  15. printLine($counter, sprintf('Checking OS (%s)', PHP_OS), TEST_PASS);
  16. $counter ++;
  17. // -----------------------------------------------------------------------------
  18. if ('cli' === strtolower(PHP_SAPI)) {
  19. $result = TEST_PASS;
  20. } else {
  21. $result = TEST_FAIL;
  22. $failed = true;
  23. }
  24. printLine($counter, sprintf('Checking SAPI (%s)', PHP_SAPI), $result);
  25. $counter ++;
  26. // -----------------------------------------------------------------------------
  27. if (1 === version_compare(PHP_VERSION, MIN_PHP_VERSION)) {
  28. $result = TEST_PASS;
  29. } else {
  30. $result = TEST_FAIL;
  31. $failed = true;
  32. }
  33. printLine($counter, sprintf('Checking PHP version (%s)', PHP_VERSION), $result);
  34. $counter ++;
  35. // -----------------------------------------------------------------------------
  36. printLine($counter, sprintf('Checking memory limit (%s)', ini_get('memory_limit')), TEST_PASS);
  37. $counter ++;
  38. // -----------------------------------------------------------------------------
  39. if (in_array('http', stream_get_wrappers())) {
  40. $result = TEST_PASS;
  41. } else {
  42. $result = TEST_FAIL;
  43. $failed = true;
  44. }
  45. printLine($counter, 'Checking HTTP stream wrapper', $result);
  46. $counter ++;
  47. // -----------------------------------------------------------------------------
  48. if (in_array('https', stream_get_wrappers())) {
  49. $result = TEST_PASS;
  50. } else {
  51. $result = TEST_FAIL;
  52. $failed = true;
  53. }
  54. printLine($counter, 'Checking HTTPS stream wrapper', $result);
  55. $counter ++;
  56. // -----------------------------------------------------------------------------
  57. if (true === method_exists('Zend_Debug', 'dump')) {
  58. $result = TEST_PASS;
  59. } else {
  60. $result = TEST_FAIL;
  61. $failed = true;
  62. }
  63. printLine($counter, 'Checking Zend Framework path', $result);
  64. $counter ++;
  65. // -----------------------------------------------------------------------------
  66. if (1 === version_compare(Zend_Version::VERSION, MIN_ZF_VERSION)) {
  67. $result = TEST_PASS;
  68. } else {
  69. $result = TEST_FAIL;
  70. $failed = true;
  71. }
  72. printLine($counter, sprintf('Checking Zend Framework version (%s)', Zend_Version::VERSION), $result);
  73. $counter ++;
  74. // -----------------------------------------------------------------------------
  75. if (extension_loaded('soap')) {
  76. $result = TEST_PASS;
  77. } else {
  78. $result = TEST_FAIL;
  79. $failed = true;
  80. }
  81. printLine($counter, 'Checking SOAP extension', $result);
  82. $counter ++;
  83. // -----------------------------------------------------------------------------
  84. if (extension_loaded('dom')) {
  85. $result = TEST_PASS;
  86. } else {
  87. $result = TEST_FAIL;
  88. $failed = true;
  89. }
  90. printLine($counter, 'Checking DOM extension', $result);
  91. $counter ++;
  92. // -----------------------------------------------------------------------------
  93. if (extension_loaded('simplexml')) {
  94. $result = TEST_PASS;
  95. } else {
  96. $result = TEST_FAIL;
  97. $failed = true;
  98. }
  99. printLine($counter, 'Checking SimpleXML extension', $result);
  100. $counter ++;
  101. // -----------------------------------------------------------------------------
  102. if (extension_loaded('libxml')) {
  103. $result = TEST_PASS;
  104. } else {
  105. $result = TEST_FAIL;
  106. $failed = true;
  107. }
  108. printLine($counter, 'Checking libXML extension', $result);
  109. $counter ++;
  110. // -----------------------------------------------------------------------------
  111. $geoData = @file_get_contents('http://ipinfodb.com/ip_query.php');
  112. $keys = array (
  113. 'Ip' => 'IP address',
  114. 'City' => 'city',
  115. 'RegionName' => 'region',
  116. 'CountryName' => 'country'
  117. );
  118. if (false !== $geoData) {
  119. $simplexml = new SimpleXMLElement($geoData);
  120. foreach ($keys as $key => $value) {
  121. printLine($counter, sprintf('Checking your %s (%s)', $keys[$key], $simplexml->$key), TEST_PASS);
  122. $counter ++;
  123. }
  124. } else {
  125. printLine($counter, 'Checking your geo data', TEST_FAIL);
  126. $failed = true;
  127. }
  128. // -----------------------------------------------------------------------------
  129. $microtime = microtime(true);
  130. if (false !== @file_get_contents(Zend_Service_LiveDocx_MailMerge::ENDPOINT)) {
  131. $duration = microtime(true) - $microtime;
  132. $result = TEST_PASS;
  133. } else {
  134. $duration = -1;
  135. $result = TEST_FAIL;
  136. $failed = true;
  137. }
  138. printLine($counter, sprintf('Checking backend WSDL (%01.2fs)', $duration), $result);
  139. $counter ++;
  140. // -----------------------------------------------------------------------------
  141. if (defined('Demos_Zend_Service_LiveDocx_Helper::USERNAME') &&
  142. defined('Demos_Zend_Service_LiveDocx_Helper::PASSWORD')) {
  143. $result = TEST_PASS;
  144. } else {
  145. $result = TEST_FAIL;
  146. $failed = true;
  147. }
  148. printLine($counter, 'Checking backend credentials are defined', $result);
  149. $counter ++;
  150. // -----------------------------------------------------------------------------
  151. $errorMessage = null;
  152. try {
  153. $microtime = microtime(true);
  154. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
  155. array (
  156. 'username' => Demos_Zend_Service_LiveDocx_Helper::USERNAME,
  157. 'password' => Demos_Zend_Service_LiveDocx_Helper::PASSWORD
  158. )
  159. );
  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('Instantiating Zend_Service_LiveDocx_MailMerge object (%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 $counter
  185. * @param $testString
  186. * @param $testResult
  187. */
  188. function printLine($counter, $testString, $testResult)
  189. {
  190. $lineLength = Demos_Zend_Service_LiveDocx_Helper::LINE_LENGTH;
  191. // counter result
  192. $padding = $lineLength - (4 + strlen(TEST_PASS));
  193. $counter = sprintf('%2s: ', $counter);
  194. $testString = str_pad($testString, $padding, '.', STR_PAD_RIGHT);
  195. printf('%s%s%s%s', $counter, $testString, $testResult, PHP_EOL);
  196. }
  197. // -----------------------------------------------------------------------------