Массив кодов:
$codes_texts = [
0 => 'OK',
1 => 'UNSUPPORTED_PROTOCOL',
2 => 'FAILED_INIT',
3 => 'URL_MALFORMAT',
4 => 'URL_MALFORMAT_USER',
5 => 'COULDNT_RESOLVE_PROXY',
6 => 'COULDNT_RESOLVE_HOST',
7 => 'COULDNT_CONNECT',
8 => 'FTP_WEIRD_SERVER_REPLY',
9 => 'FTP_ACCESS_DENIED',
10 => 'FTP_USER_PASSWORD_INCORRECT',
11 => 'FTP_WEIRD_PASS_REPLY',
12 => 'FTP_WEIRD_USER_REPLY',
13 => 'FTP_WEIRD_PASV_REPLY',
14 => 'FTP_WEIRD_227_FORMAT',
15 => 'FTP_CANT_GET_HOST',
16 => 'FTP_CANT_RECONNECT',
17 => 'FTP_COULDNT_SET_BINARY',
18 => 'PARTIAL_FILE',
19 => 'FTP_COULDNT_RETR_FILE',
20 => 'FTP_WRITE_ERROR',
21 => 'FTP_QUOTE_ERROR',
22 => 'HTTP_NOT_FOUND',
23 => 'WRITE_ERROR',
24 => 'MALFORMAT_USER',
25 => 'FTP_COULDNT_STOR_FILE',
26 => 'READ_ERROR',
27 => 'OUT_OF_MEMORY',
28 => 'OPERATION_TIMEOUTED',
29 => 'FTP_COULDNT_SET_ASCII',
30 => 'FTP_PORT_FAILED',
31 => 'FTP_COULDNT_USE_REST',
32 => 'FTP_COULDNT_GET_SIZE',
33 => 'HTTP_RANGE_ERROR',
34 => 'HTTP_POST_ERROR',
35 => 'SSL_CONNECT_ERROR',
36 => 'FTP_BAD_DOWNLOAD_RESUME',
37 => 'FILE_COULDNT_READ_FILE',
38 => 'LDAP_CANNOT_BIND',
39 => 'LDAP_SEARCH_FAILED',
40 => 'LIBRARY_NOT_FOUND',
41 => 'FUNCTION_NOT_FOUND',
42 => 'ABORTED_BY_CALLBACK',
43 => 'BAD_FUNCTION_ARGUMENT',
44 => 'BAD_CALLING_ORDER',
45 => 'HTTP_PORT_FAILED',
46 => 'BAD_PASSWORD_ENTERED',
47 => 'TOO_MANY_REDIRECTS',
48 => 'UNKNOWN_TELNET_OPTION',
49 => 'TELNET_OPTION_SYNTAX',
50 => 'OBSOLETE',
51 => 'SSL_PEER_CERTIFICATE',
52 => 'GOT_NOTHING',
53 => 'SSL_ENGINE_NOTFOUND',
54 => 'SSL_ENGINE_SETFAILED',
55 => 'SEND_ERROR',
56 => 'RECV_ERROR',
57 => 'SHARE_IN_USE',
58 => 'SSL_CERTPROBLEM',
59 => 'SSL_CIPHER',
60 => 'SSL_CACERT',
61 => 'BAD_CONTENT_ENCODING',
62 => 'LDAP_INVALID_URL',
63 => 'FILESIZE_EXCEEDED',
64 => 'FTP_SSL_FAILED',
];
Сценарий:
<code>$urls = array(
"http://php.net/",
"http://404.php.net/",
"httpnot://php.net/",
);
$mh = curl_multi_init();
$codes = [];
$result = [];
$connects = [];
foreach ($urls as $i => $url) {
$connects[$i] = curl_init($url);
curl_setopt($connects[$i], CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($mh, $connects[$i]);
}
do {
$status = curl_multi_exec($mh, $active);
$info = curl_multi_info_read($mh, $count);
if ($info !== false) {
$codes[(int)$info['handle']] = (int)$info['result'];
}
}
while ($status === CURLM_CALL_MULTI_PERFORM || $active || $count);
foreach ($connects as $i => $connect) {
$result[$i] = [
'url' => $urls[$i],
'code' => $codes[(int)$connect], // 0 - 64 = curl_errno
'code_text' => $codes_texts[$codes[(int)$connect]],
'body_len' => strlen(curl_multi_getcontent($connect)),
];
curl_close($connect);
}
curl_multi_close($mh);
echo "<pre>" . var_export($result, 1) . "
";
Результат:
array (
0 =>
array (
'url' => 'http://php.net/',
'code' => 0,
'code_text' => 'OK',
'body_len' => 34462,
),
1 =>
array (
'url' => 'http://404.php.net/',
'code' => 6,
'code_text' => 'COULDNT_RESOLVE_HOST',
'body_len' => 0,
),
2 =>
array (
'url' => 'httpnot://php.net/',
'code' => 1,
'code_text' => 'UNSUPPORTED_PROTOCOL',
'body_len' => 0,
),
)