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