47c320e0b7ad18547df51ca8a6534d21ad9d1b8a
[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-2008 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, '4') < 0)
33     {
34       $tests['php_version']['status'] = 0;
35       $tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 4.2 or later';
36     }
37     else if (version_compare($ver, '4.2') < 0)
38     {
39       $tests['php_version']['status'] = 1;
40       $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";
41     }
42     else if (version_compare($ver, '5.0.3') < 0)
43     {
44       $tests['php_version']['status'] = 1;
45       $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";
46     }
47     else
48     {
49       $tests['php_version']['status'] = 2;
50       $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
51     }
52
53     // test for zlib
54     $tests['zlib'] = array();
55     if (!function_exists('gzinflate'))
56     {
57       $tests['zlib']['status'] = 0;
58       $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)";
59     }
60     else
61     {
62       $tests['zlib']['status'] = 2;
63       $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";
64     }
65
66     // test for diaply of php errors in xml reponse
67     if (ini_get('display_errors'))
68     {
69       if (intval(ini_get('error_reporting')) && E_NOTICE )
70       {
71         $tests['display_errors']['status'] = 1;
72         $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";
73       }
74       else
75       {
76         $tests['display_errors']['status'] = 1;
77         $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";
78       }
79     }
80
81   }
82   else
83   {
84
85     // test for php version
86     $ver = phpversion();
87     $tests['php_version'] = array();
88     $tests['php_version']['description'] = 'PHP version found: '.$ver.".\n\n";
89     if (version_compare($ver, '4') < 0)
90     {
91       $tests['php_version']['status'] = 0;
92       $tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 4.2 or later';
93     }
94     else if (version_compare($ver, '4.2') < 0)
95     {
96       $tests['php_version']['status'] = 1;
97       $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";
98     }
99     else
100     {
101       $tests['php_version']['status'] = 2;
102       $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
103     }
104
105     // test for zlib
106     $tests['zlib'] = array();
107     if (!function_exists('gzinflate'))
108     {
109       $tests['zlib']['status'] = 0;
110       $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)";
111     }
112     else
113     {
114       $tests['zlib']['status'] = 2;
115       $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";
116     }
117
118     // test for CURL
119     $tests['curl'] = array();
120     if (!extension_loaded('curl'))
121     {
122       $tests['curl']['status'] = 0;
123       $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";
124     }
125     else
126     {
127       $info = curl_version();
128       $tests['curl']['status'] = 2;
129       $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";
130       if (version_compare($ver, '4.3.8') < 0)
131       {
132         $tests['curl']['status'] = 1;
133         $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support keep-alives";
134       }
135       if (!((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
136       {
137         $tests['curl']['status'] = 1;
138         $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages";
139       }
140       if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version'])))
141       {
142         $tests['curl']['status'] = 1;
143         $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support HTTPS connections";
144       }
145     }
146
147   }
148   return $tests;
149 }
150
151 ?>
152 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
153 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
154 <head>
155 <title>PHP XMLRPC compatibility assessment</title>
156 <style type="text/css">
157 body, html {background-color: white; font-family: Arial, Verdana, Geneva, sans-serif; font-size: small; }
158 table { border: 1px solid gray; padding: 0;}
159 thead { background-color: silver; color: black; }
160 td { margin: 0; padding: 0.5em; }
161 tbody td { border-top: 1px solid gray; }
162 .res0 { background-color: red; color: black; border-right: 1px solid gray; }
163 .res1 { background-color: yellow; color: black; border-right: 1px solid gray; }
164 .res2 { background-color: green; color: black; border-right: 1px solid gray; }
165 .result { white-space: pre; }
166 </style>
167 </head>
168 <body>
169 <h1>PHPXMLRPC compatibility assessment with the current PHP install</h1>
170 <h4>For phpxmlrpc version 2.0 or later</h4>
171 <h3>Server usage</h3>
172 <table cellspacing="0">
173 <thead>
174 <tr><td>Test</td><td>Result</td></tr>
175 </thead>
176 <tbody>
177 <?php
178   $res = phpxmlrpc_verify_compat('server');
179   foreach($res as $test => $result)
180   {
181       echo '<tr><td class="res'.$result['status'].'">'.htmlspecialchars($test).'</td><td class="result">'.htmlspecialchars($result['description'])."</td></tr>\n";
182   }
183 ?>
184 </tbody>
185 </table>
186 <h3>Client usage</h3>
187 <table cellspacing="0">
188 <thead>
189 <tr><td>Test</td><td>Result</td></tr>
190 </thead>
191 <tbody>
192 <?php
193   $res = phpxmlrpc_verify_compat('client');
194   foreach($res as $test => $result)
195   {
196       echo '<tr><td class="res'.$result['status'].'">'.htmlspecialchars($test).'</td><td class="result">'.htmlspecialchars($result['description'])."</td></tr>\n";
197   }
198 ?>
199 </tbody>
200 </table>
201 </body>
202 </html>