- remove testing for older versions of php
[plcapi.git] / test / verify_compat.php
1 <?php
2 /**
3  * Verify compatibility level of current php install with php-xmlrpc lib
4  *
5  * @version $Id$
6  * @author Gaetano Giunta
7  * @copyright (C) 2006-2009 G. Giunta
8  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
9  */
10
11 // be backward compat up to version 4.0.5...
12 if (!function_exists('version_compare'))
13 {
14                 // give an opportunity to user to specify where to include other files from
15   if(!defined('PHP_XMLRPC_COMPAT_DIR'))
16   {
17     define('PHP_XMLRPC_COMPAT_DIR',dirname(__FILE__).'/compat/');
18   }
19   include(PHP_XMLRPC_COMPAT_DIR.'version_compare.php');
20 }
21
22 function phpxmlrpc_verify_compat($mode='client')
23 {
24   $tests = array();
25
26   if ($mode == 'server')
27   {
28     // test for php version
29     $ver = phpversion();
30     $tests['php_version'] = array();
31     $tests['php_version']['description'] = 'PHP version found: '.$ver.".\n\n";
32     if (version_compare($ver, '5') < 0)
33     {
34       $tests['php_version']['status'] = 0;
35       $tests['php_version']['description'] .= 'This version of PHP is not compatible with this release of the PHP XMLRPC library. Please upgrade to php 5 or later';
36     }
37     else if (version_compare($ver, '5.0.3') < 0)
38     {
39       $tests['php_version']['status'] = 1;
40       $tests['php_version']['description'] .= "This version of PHP is almost completely compatible with the PHP XMLRPC library.\nThe only unavailable function is automatic mapping of php functions to xmlrpc methods";
41     }
42     else
43     {
44       $tests['php_version']['status'] = 2;
45       $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
46     }
47
48     // test for zlib
49     $tests['zlib'] = array();
50     if (!function_exists('gzinflate'))
51     {
52       $tests['zlib']['status'] = 0;
53       $tests['zlib']['description'] = "The zlib extension is not enabled.\n\nYou will not be able to receive compressed requests or send compressed responses, unless using the cURL library (for 'HTTPS' and 'HTTP 1.1' connections)";
54     }
55     else
56     {
57       $tests['zlib']['status'] = 2;
58       $tests['zlib']['description'] = "The zlib extension is enabled.\n\nYou will be able to receive compressed requests and send compressed responses for the 'HTTP' protocol";
59     }
60
61     // test for diaply of php errors in xml reponse
62     if (ini_get('display_errors'))
63     {
64       if (intval(ini_get('error_reporting')) && E_NOTICE )
65       {
66         $tests['display_errors']['status'] = 1;
67         $tests['display_errors']['description'] = "Error reporting level includes E_NOTICE errors, and display_errors is set to ON.\n\nAny error, warning or notice raised while executing php code exposed as xmlrpc method will result in an invalid xmlrpc response";
68       }
69       else
70       {
71         $tests['display_errors']['status'] = 1;
72         $tests['display_errors']['description'] = "display_errors is set to ON.\n\nAny error raised while executing php code exposed as xmlrpc method will result in an invalid xmlrpc response";
73       }
74     }
75
76   }
77   else
78   {
79
80     // test for php version
81     $ver = phpversion();
82     $tests['php_version'] = array();
83     $tests['php_version']['description'] = 'PHP version found: '.$ver.".\n\n";
84     if (version_compare($ver, '4') < 0)
85     {
86       $tests['php_version']['status'] = 0;
87       $tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 4.2 or later';
88     }
89     else if (version_compare($ver, '4.2') < 0)
90     {
91       $tests['php_version']['status'] = 1;
92       $tests['php_version']['description'] .= "This version of PHP is partially compatible with the PHP XMLRPC library.\nIn order to use the library, you will need to make sure the files from the compat directory are available on your server";
93     }
94     else
95     {
96       $tests['php_version']['status'] = 2;
97       $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
98     }
99
100     // test for zlib
101     $tests['zlib'] = array();
102     if (!function_exists('gzinflate'))
103     {
104       $tests['zlib']['status'] = 0;
105       $tests['zlib']['description'] = "The zlib extension is not enabled.\n\nYou will not be able to send compressed requests or receive compressed responses, unless using the cURL library (for 'HTTPS' and 'HTTP 1.1' connections)";
106     }
107     else
108     {
109       $tests['zlib']['status'] = 2;
110       $tests['zlib']['description'] = "The zlib extension is enabled.\n\nYou will be able to send compressed requests and receive compressed responses for the 'HTTP' protocol";
111     }
112
113     // test for CURL
114     $tests['curl'] = array();
115     if (!extension_loaded('curl'))
116     {
117       $tests['curl']['status'] = 0;
118       $tests['curl']['description'] = "The cURL extension is not enabled.\n\nYou will not be able to send and receive messages using 'HTTPS' and 'HTTP 1.1' protocols";
119     }
120     else
121     {
122       $info = curl_version();
123       $tests['curl']['status'] = 2;
124       $tests['curl']['description'] = "The cURL extension is enabled.\n\nYou will be able to send and receive messages using 'HTTPS' and 'HTTP 1.1' protocols";
125       if (version_compare($ver, '4.3.8') < 0)
126       {
127         $tests['curl']['status'] = 1;
128         $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support keep-alives";
129       }
130       if (!((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
131       {
132         $tests['curl']['status'] = 1;
133         $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages";
134       }
135       if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version'])))
136       {
137         $tests['curl']['status'] = 1;
138         $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support HTTPS connections";
139       }
140     }
141
142   }
143   return $tests;
144 }
145
146 ?>
147 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
148 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
149 <head>
150 <title>PHP XMLRPC compatibility assessment</title>
151 <style type="text/css">
152 body, html {background-color: white; font-family: Arial, Verdana, Geneva, sans-serif; font-size: small; }
153 table { border: 1px solid gray; padding: 0;}
154 thead { background-color: silver; color: black; }
155 td { margin: 0; padding: 0.5em; }
156 tbody td { border-top: 1px solid gray; }
157 .res0 { background-color: red; color: black; border-right: 1px solid gray; }
158 .res1 { background-color: yellow; color: black; border-right: 1px solid gray; }
159 .res2 { background-color: green; color: black; border-right: 1px solid gray; }
160 .result { white-space: pre; }
161 </style>
162 </head>
163 <body>
164 <h1>PHPXMLRPC compatibility assessment with the current PHP install</h1>
165 <h4>For phpxmlrpc version 2.0 or later</h4>
166 <h3>Server usage</h3>
167 <table cellspacing="0">
168 <thead>
169 <tr><td>Test</td><td>Result</td></tr>
170 </thead>
171 <tbody>
172 <?php
173   $res = phpxmlrpc_verify_compat('server');
174   foreach($res as $test => $result)
175   {
176       echo '<tr><td class="res'.$result['status'].'">'.htmlspecialchars($test).'</td><td class="result">'.htmlspecialchars($result['description'])."</td></tr>\n";
177   }
178 ?>
179 </tbody>
180 </table>
181 <h3>Client usage</h3>
182 <table cellspacing="0">
183 <thead>
184 <tr><td>Test</td><td>Result</td></tr>
185 </thead>
186 <tbody>
187 <?php
188   $res = phpxmlrpc_verify_compat('client');
189   foreach($res as $test => $result)
190   {
191       echo '<tr><td class="res'.$result['status'].'">'.htmlspecialchars($test).'</td><td class="result">'.htmlspecialchars($result['description'])."</td></tr>\n";
192   }
193 ?>
194 </tbody>
195 </table>
196 </body>
197 </html>