Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
#! /usr/bin/env php
2
<?php
3
 
4
// Required
5
$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '5.2.0', '>='));
6
$simplexml_ok = extension_loaded('simplexml');
7
$dom_ok = extension_loaded('dom');
8
$json_ok = (extension_loaded('json') && function_exists('json_encode') && function_exists('json_decode'));
9
$spl_ok = extension_loaded('spl');
10
$pcre_ok = extension_loaded('pcre');
11
if (function_exists('curl_version'))
12
{
13
	$curl_version = curl_version();
14
	$curl_ok = (function_exists('curl_exec') && in_array('https', $curl_version['protocols'], true));
15
}
16
$file_ok = (function_exists('file_get_contents') && function_exists('file_put_contents'));
17
 
18
// Optional, but recommended
19
$openssl_ok = (extension_loaded('openssl') && function_exists('openssl_sign'));
20
$zlib_ok = extension_loaded('zlib');
21
 
22
// Optional
23
$apc_ok = extension_loaded('apc');
24
$xcache_ok = extension_loaded('xcache');
25
$memcached_ok = extension_loaded('memcached');
26
$memcache_ok = extension_loaded('memcache');
27
$mc_ok = ($memcache_ok || $memcached_ok);
28
$pdo_ok = extension_loaded('pdo');
29
$pdo_sqlite_ok = extension_loaded('pdo_sqlite');
30
$sqlite2_ok = extension_loaded('sqlite');
31
$sqlite3_ok = extension_loaded('sqlite3');
32
$sqlite_ok = ($pdo_ok && $pdo_sqlite_ok && ($sqlite2_ok || $sqlite3_ok));
33
 
34
// Other
35
$int64_ok = (PHP_INT_MAX === 9223372036854775807);
36
$ini_memory_limit = get_ini('memory_limit');
37
$ini_open_basedir = get_ini('open_basedir');
38
$ini_safe_mode = get_ini('safe_mode');
39
$ini_zend_enable_gc = get_ini('zend.enable_gc');
40
 
41
function get_ini($config)
42
{
43
	$cfg_value = ini_get($config);
44
 
45
	if ($cfg_value === false || $cfg_value === '' || $cfg_value === 0)
46
	{
47
		return false;
48
	}
49
	elseif ($cfg_value === true || $cfg_value === '1' || $cfg_value === 1)
50
	{
51
		return true;
52
	}
53
}
54
 
55
function is_windows()
56
{
57
	return strtolower(substr(PHP_OS, 0, 3)) === 'win';
58
}
59
 
60
// CLI display
61
function success($s = 'Yes')
62
{
63
	return is_windows() ? $s : "\033[1;37m\033[42m " . $s . " \033[0m";
64
}
65
 
66
function info($s = 'Info')
67
{
68
	return is_windows() ? $s : "\033[1;37m\033[44m " . $s . " \033[0m";
69
}
70
 
71
function failure($s = 'No ')
72
{
73
	return is_windows() ? $s : "\033[1;37m\033[41m " . $s . " \033[0m";
74
}
75
 
76
/////////////////////////////////////////////////////////////////////////
77
 
78
echo PHP_EOL;
79
 
80
echo info('AWS SDK for PHP') . PHP_EOL;
81
echo 'PHP Environment Compatibility Test (CLI)' . PHP_EOL;
82
echo '----------------------------------------' . PHP_EOL;
83
echo PHP_EOL;
84
 
85
echo 'PHP 5.2 or newer............ ' . ($php_ok ? (success() . ' ' . phpversion()) : failure()) . PHP_EOL;
86
echo '64-bit architecture......... ' . ($int64_ok ? success() : failure()) . (is_windows() ? ' (see note below)' : '') . PHP_EOL;
87
echo 'cURL with SSL............... ' . ($curl_ok ? (success() . ' ' . $curl_version['version'] . ' (' . $curl_version['ssl_version'] . ')') : failure($curl_version['version'] . (in_array('https', $curl_version['protocols'], true) ? ' (with ' . $curl_version['ssl_version'] . ')' : ' (without SSL)'))) . PHP_EOL;
88
echo 'Standard PHP Library........ ' . ($spl_ok ? success() : failure()) . PHP_EOL;
89
echo 'SimpleXML................... ' . ($simplexml_ok ? success() : failure()) . PHP_EOL;
90
echo 'DOM......................... ' . ($dom_ok ? success() : failure()) . PHP_EOL;
91
echo 'JSON........................ ' . ($json_ok ? success() : failure()) . PHP_EOL;
92
echo 'PCRE........................ ' . ($pcre_ok ? success() : failure()) . PHP_EOL;
93
echo 'File system read/write...... ' . ($file_ok ? success() : failure()) . PHP_EOL;
94
echo 'OpenSSL extension........... ' . ($openssl_ok ? success() : failure()) . PHP_EOL;
95
echo 'Zlib........................ ' . ($zlib_ok ? success() : failure()) . PHP_EOL;
96
echo 'APC......................... ' . ($apc_ok ? success() : failure()) . PHP_EOL;
97
echo 'XCache...................... ' . ($xcache_ok ? success() : failure()) . PHP_EOL;
98
echo 'Memcache.................... ' . ($memcache_ok ? success() : failure()) . PHP_EOL;
99
echo 'Memcached................... ' . ($memcached_ok ? success() : failure()) . PHP_EOL;
100
echo 'PDO......................... ' . ($pdo_ok ? success() : failure()) . PHP_EOL;
101
echo 'SQLite 2.................... ' . ($sqlite2_ok ? success() : failure()) . PHP_EOL;
102
echo 'SQLite 3.................... ' . ($sqlite3_ok ? success() : failure()) . PHP_EOL;
103
echo 'PDO-SQLite driver........... ' . ($pdo_sqlite_ok ? success() : failure()) . PHP_EOL;
104
echo 'open_basedir disabled....... ' . (!$ini_open_basedir ? success() : failure()) . PHP_EOL;
105
echo 'safe_mode disabled.......... ' . (!$ini_safe_mode ? success() : failure()) . PHP_EOL;
106
echo 'Garbage Collector enabled... ' . ($ini_zend_enable_gc ? success() : failure()) . PHP_EOL;
107
 
108
// Test SSL cert
109
if (!is_windows())
110
{
111
	$ch = curl_init();
112
	curl_setopt($ch, CURLOPT_URL, 'https://email.us-east-1.amazonaws.com');
113
	curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
114
	curl_setopt($ch, CURLOPT_HEADER, false);
115
	curl_setopt($ch, CURLOPT_NOBODY, true);
116
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
117
	curl_setopt($ch, CURLOPT_TIMEOUT, 5184000);
118
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
119
	curl_setopt($ch, CURLOPT_NOSIGNAL, true);
120
	curl_setopt($ch, CURLOPT_USERAGENT, 'aws-sdk-php/compat-cli');
121
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
122
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
123
	curl_setopt($ch, CURLOPT_VERBOSE, false);
124
	curl_exec($ch);
125
	$ssl_result = !(curl_getinfo($ch, CURLINFO_SSL_VERIFYRESULT) === 0);
126
	curl_close($ch);
127
 
128
	echo 'Valid SSL certificate....... ' . ($ssl_result ? failure() : success()) . PHP_EOL;
129
}
130
else
131
{
132
	$ssl_result = false;
133
	echo 'Valid SSL certificate....... ' . failure() . ' (will use the bundled certificate instead)' . PHP_EOL;
134
}
135
 
136
echo PHP_EOL;
137
 
138
echo '----------------------------------------' . PHP_EOL;
139
echo PHP_EOL;
140
 
141
if ($php_ok && $curl_ok && $simplexml_ok && $dom_ok && $spl_ok && $json_ok && $pcre_ok && $file_ok)
142
{
143
	echo success('Your environment meets the minimum requirements for using the AWS SDK for PHP!') . PHP_EOL . PHP_EOL;
144
	if (version_compare(PHP_VERSION, '5.3.0') < 0) { echo '* You\'re still running PHP ' . PHP_VERSION . '. The PHP 5.2 family is no longer supported' . PHP_EOL . '  by the PHP team, and future versions of the AWS SDK for PHP will *require*' . PHP_EOL . '  PHP 5.3 or newer.' . PHP_EOL . PHP_EOL; }
145
	if ($openssl_ok) { echo '* The OpenSSL extension is installed. This will allow you to use CloudFront' . PHP_EOL . '  Private URLs and decrypt Windows instance passwords.' . PHP_EOL . PHP_EOL; }
146
	if ($zlib_ok) {    echo '* The Zlib extension is installed. The SDK will request gzipped data' . PHP_EOL . '  whenever possible.' . PHP_EOL . PHP_EOL; }
147
	if (!$int64_ok) {  echo '* You\'re running on a 32-bit system. This means that PHP does not correctly' . PHP_EOL . '  handle files larger than 2GB (this is a well-known PHP issue).' . PHP_EOL . PHP_EOL; }
148
	if (!$int64_ok && is_windows()) {  echo '* Note that PHP on Microsoft(R) Windows(R) does not support 64-bit integers' . PHP_EOL . '  at all, even if both the hardware and PHP are 64-bit. http://j.mp/php64win' . PHP_EOL . PHP_EOL; }
149
 
150
	if ($ini_open_basedir || $ini_safe_mode) { echo '* You have open_basedir or safe_mode enabled in your php.ini file. Sometimes' . PHP_EOL . '  PHP behaves strangely when these settings are enabled. Disable them if you can.' . PHP_EOL . PHP_EOL; }
151
	if (!$ini_zend_enable_gc) { echo '* The PHP garbage collector (available in PHP 5.3+) is not enabled in your' . PHP_EOL . '  php.ini file. Enabling zend.enable_gc will provide better memory management' . PHP_EOL . '  in the PHP core.' . PHP_EOL . PHP_EOL; }
152
 
153
	$storage_types = array();
154
	if ($file_ok) { $storage_types[] = 'The file system'; }
155
	if ($apc_ok) { $storage_types[] = 'APC'; }
156
	if ($xcache_ok) { $storage_types[] = 'XCache'; }
157
	if ($sqlite_ok && $sqlite3_ok) { $storage_types[] = 'SQLite 3'; }
158
	elseif ($sqlite_ok && $sqlite2_ok) { $storage_types[] = 'SQLite 2'; }
159
	if ($memcached_ok) { $storage_types[] = 'Memcached'; }
160
	elseif ($memcache_ok) { $storage_types[] = 'Memcache'; }
161
	echo '* Storage types available for response caching:' . PHP_EOL . '  ' . implode(', ', $storage_types) . PHP_EOL . PHP_EOL;
162
 
163
	if (!$openssl_ok) { echo '* You\'re missing the OpenSSL extension, which means that you won\'t be able' . PHP_EOL . '  to take advantage of CloudFront Private URLs or Windows password decryption.' . PHP_EOL . PHP_EOL; }
164
	if (!$zlib_ok) {    echo '* You\'re missing the Zlib extension, which means that the SDK will be unable' . PHP_EOL . '  to request gzipped data from Amazon and you won\'t be able to take advantage' . PHP_EOL . '  of compression with the response caching feature.' . PHP_EOL . PHP_EOL; }
165
}
166
else
167
{
168
	if (!$php_ok) {       echo '* ' . failure('PHP:') . ' You are running an unsupported version of PHP.' . PHP_EOL . PHP_EOL; }
169
	if (!$curl_ok) {      echo '* ' . failure('cURL:') . ' The cURL extension is not available. Without cURL, the SDK cannot' . PHP_EOL . '  connect to -- or authenticate with -- Amazon\'s services.' . PHP_EOL . PHP_EOL; }
170
	if (!$simplexml_ok) { echo '* ' . failure('SimpleXML:') . ': The SimpleXML extension is not available. Without SimpleXML,' . PHP_EOL . '  the SDK cannot parse the XML responses from Amazon\'s services.' . PHP_EOL . PHP_EOL; }
171
	if (!$dom_ok) {       echo '* ' . failure('DOM:') . ': The DOM extension is not available. Without DOM, the SDK' . PHP_EOL . '  Without DOM, the SDK cannot transliterate JSON responses from Amazon\'s' . PHP_EOL . '  services into the common SimpleXML-based pattern used throughout the SDK.' . PHP_EOL . PHP_EOL; }
172
	if (!$spl_ok) {       echo '* ' . failure('SPL:') . ' Standard PHP Library support is not available. Without SPL support,' . PHP_EOL . '  the SDK cannot autoload the required PHP classes.' . PHP_EOL . PHP_EOL; }
173
	if (!$json_ok) {      echo '* ' . failure('JSON:') . ' JSON support is not available. AWS leverages JSON heavily in many' . PHP_EOL . '  of its services.' . PHP_EOL . PHP_EOL; }
174
	if (!$pcre_ok) {      echo '* ' . failure('PCRE:') . ' Your PHP installation doesn\'t support Perl-Compatible Regular' . PHP_EOL . '  Expressions (PCRE). Without PCRE, the SDK cannot do any filtering via' . PHP_EOL . '  regular expressions.' . PHP_EOL . PHP_EOL; }
175
	if (!$file_ok) {      echo '* ' . failure('File System Read/Write:') . ' The file_get_contents() and/or file_put_contents()' . PHP_EOL . '  functions have been disabled. Without them, the SDK cannot read from,' . PHP_EOL . '  or write to, the file system.' . PHP_EOL . PHP_EOL; }
176
}
177
 
178
echo '----------------------------------------' . PHP_EOL;
179
echo PHP_EOL;
180
 
181
if ($php_ok && $int64_ok && $curl_ok && $simplexml_ok && $dom_ok && $spl_ok && $json_ok && $pcre_ok && $file_ok && $openssl_ok && $zlib_ok && ($apc_ok || $xcache_ok || $mc_ok || $sqlite_ok))
182
{
183
	echo success('Bottom Line: Yes, you can!') . PHP_EOL;
184
	echo PHP_EOL;
185
	echo 'Your PHP environment is ready to go, and can take advantage of all possible features!' . PHP_EOL;
186
 
187
	echo PHP_EOL;
188
	echo info('Recommended settings for config.inc.php') . PHP_EOL;
189
	echo PHP_EOL;
190
 
191
	echo "CFCredentials::set(array(" . PHP_EOL;
192
	echo "    '@default' => array(" . PHP_EOL;
193
	echo "        'key' => 'aws-key'," . PHP_EOL;
194
	echo "        'secret' => 'aws-secret'," . PHP_EOL;
195
	echo "        'default_cache_config' => ";
196
	if ($apc_ok) echo success('\'apc\'');
197
	elseif ($xcache_ok) echo success('\'xcache\'');
198
	elseif ($file_ok) echo success('\'/path/to/cache/folder\'');
199
	echo "," . PHP_EOL;
200
	echo "        'certificate_authority' => " . success($ssl_result ? 'true' : 'false') . PHP_EOL;
201
	echo "    )" . PHP_EOL;
202
	echo "));" . PHP_EOL;
203
}
204
elseif ($php_ok && $curl_ok && $simplexml_ok && $dom_ok && $spl_ok && $json_ok && $pcre_ok && ($apc_ok || $xcache_ok || $sqlite_ok))
205
{
206
	echo success('Bottom Line: Yes, you can!') . PHP_EOL;
207
	echo PHP_EOL;
208
	echo 'Your PHP environment is ready to go! There are a couple of minor features that' . PHP_EOL . 'you won\'t be able to take advantage of, but nothing that\'s a show-stopper.' . PHP_EOL;
209
 
210
	echo PHP_EOL;
211
	echo info('Recommended settings for config.inc.php') . PHP_EOL;
212
	echo PHP_EOL;
213
 
214
	echo "CFCredentials::set(array(" . PHP_EOL;
215
	echo "    '@default' => array(" . PHP_EOL;
216
	echo "        'key' => 'aws-key'," . PHP_EOL;
217
	echo "        'secret' => 'aws-secret'," . PHP_EOL;
218
	echo "        'default_cache_config' => ";
219
	if ($apc_ok) echo success('\'apc\'');
220
	elseif ($xcache_ok) echo success('\'xcache\'');
221
	elseif ($file_ok) echo success('\'/path/to/cache/folder\'');
222
	echo "," . PHP_EOL;
223
	echo "        'certificate_authority' => " . ($ssl_result ? 'false' : 'true') . PHP_EOL;
224
	echo "    )" . PHP_EOL;
225
	echo "));" . PHP_EOL;
226
}
227
else
228
{
229
	echo failure('Bottom Line: We\'re sorry...') . PHP_EOL;
230
	echo 'Your PHP environment does not support the minimum requirements for the ' . PHP_EOL . 'AWS SDK for PHP.' . PHP_EOL;
231
}
232
 
233
echo PHP_EOL;