Issues (320)

extras/verify_compat.php (1 issue)

Severity
1
<?php
2
/**
3
 * Verify compatibility level of current php install with php-xmlrpc lib.
4
 *
5
 * @author Gaetano Giunta
6
 * @copyright (C) 2006-2025 G. Giunta
7
 * @license code licensed under the BSD License: see file license.txt
8
 *
9
 * @todo add a test for php output buffering?
10
 * @todo check for presence of specific curl options, such as fe. the HTTP2 ones
11
 * @todo check for presence of mbstring
12
 * @todo check for presence of the xmlrpc extension
13
 * @todo improve the curl check/message: since php 5.6 we can use socket mode with https
14
 */
15
16
function phpxmlrpc_verify_compat($mode = 'client')
17
{
18
    $tests = array();
19
20
    if ($mode == 'server') {
21
        // test for php version
22
        $ver = phpversion();
23
        $tests['php_version'] = array();
24
        $tests['php_version']['description'] = 'PHP version found: ' . $ver . ".\n\n";
25
        if (version_compare($ver, '5.3.0') < 0) {
26
            $tests['php_version']['status'] = 0;
27
            $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';
28
        } else {
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
            $tests['zlib']['status'] = 0;
37
            $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)";
38
        } else {
39
            $tests['zlib']['status'] = 2;
40
            $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";
41
        }
42
43
        // test for display of php errors in xml response
44
        if (ini_get('display_errors')) {
45
            if (intval(ini_get('error_reporting')) && E_NOTICE) {
46
                $tests['display_errors']['status'] = 1;
47
                $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";
48
            } else {
49
                $tests['display_errors']['status'] = 1;
50
                $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";
51
            }
52
        }
53
    } else {
54
55
        // test for php version
56
        $ver = phpversion();
57
        $tests['php_version'] = array();
58
        $tests['php_version']['description'] = 'PHP version found: ' . $ver . ".\n\n";
59
        if (version_compare($ver, '5.3.0') < 0) {
60
            $tests['php_version']['status'] = 0;
61
            $tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 5.1.0 or later';
62
        } else {
63
            $tests['php_version']['status'] = 2;
64
            $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
65
        }
66
67
        // test for zlib
68
        $tests['zlib'] = array();
69
        if (!function_exists('gzinflate')) {
70
            $tests['zlib']['status'] = 0;
71
            $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)";
72
        } else {
73
            $tests['zlib']['status'] = 2;
74
            $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";
75
        }
76
77
        // test for CURL
78
        $tests['curl'] = array();
79
        if (!extension_loaded('curl')) {
80
            $tests['curl']['status'] = 0;
81
            $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";
82
        } else {
83
            $info = curl_version();
84
            $tests['curl']['status'] = 2;
85
            $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";
86
            if (version_compare($ver, '4.3.8') < 0) {
87
                $tests['curl']['status'] = 1;
88
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support keep-alives";
89
            }
90
            if (!((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version']))) {
0 ignored issues
show
The condition is_string($info) is always false.
Loading history...
91
                $tests['curl']['status'] = 1;
92
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages";
93
            }
94
            if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version']))) {
95
                $tests['curl']['status'] = 1;
96
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support HTTPS connections";
97
            }
98
        }
99
    }
100
101
    return $tests;
102
}
103
104
?>
105
<!DOCTYPE html>
106
<html lang="en">
107
<head>
108
    <title>PHP XMLRPC compatibility assessment</title>
109
    <style>
110
        body, html {
111
            background-color: white;
112
            font-family: Arial, Verdana, Geneva, sans-serif;
113
            font-size: small;
114
        }
115
        table {
116
            border: 1px solid gray;
117
            padding: 0;
118
        }
119
        thead {
120
            background-color: silver;
121
            color: black;
122
        }
123
        td {
124
            margin: 0;
125
            padding: 0.5em;
126
        }
127
        tbody td {
128
            border-top: 1px solid gray;
129
        }
130
        .res0 {
131
            background-color: red;
132
            color: black;
133
            border-right: 1px solid gray;
134
        }
135
        .res1 {
136
            background-color: yellow;
137
            color: black;
138
            border-right: 1px solid gray;
139
        }
140
        .res2 {
141
            background-color: green;
142
            color: black;
143
            border-right: 1px solid gray;
144
        }
145
        .result {
146
            white-space: pre;
147
        }
148
    </style>
149
</head>
150
<body>
151
<h1>PHPXMLRPC compatibility assessment with the current PHP install</h1>
152
<h4>For phpxmlrpc version 4.0 or later</h4>
153
154
<h3>Server usage</h3>
155
<table>
156
    <thead>
157
    <tr>
158
        <td>Test</td>
159
        <td>Result</td>
160
    </tr>
161
    </thead>
162
    <tbody>
163
    <?php
164
    $res = phpxmlrpc_verify_compat('server');
165
    foreach ($res as $test => $result) {
166
        echo '<tr><td class="res' . $result['status'] . '">' . htmlspecialchars($test) . '</td><td class="result">' . htmlspecialchars($result['description']) . "</td></tr>\n";
167
    }
168
    ?>
169
    </tbody>
170
</table>
171
<h3>Client usage</h3>
172
<table>
173
    <thead>
174
    <tr>
175
        <td>Test</td>
176
        <td>Result</td>
177
    </tr>
178
    </thead>
179
    <tbody>
180
    <?php
181
    $res = phpxmlrpc_verify_compat('client');
182
    foreach ($res as $test => $result) {
183
        echo '<tr><td class="res' . $result['status'] . '">' . htmlspecialchars($test) . '</td><td class="result">' . htmlspecialchars($result['description']) . "</td></tr>\n";
184
    }
185
    ?>
186
    </tbody>
187
</table>
188
</body>
189
</html>
190