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