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