-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-promise.php
42 lines (31 loc) · 941 Bytes
/
no-promise.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php declare(strict_types=1);
require_once 'vendor/autoload.php';
$urls = [
'https://example.com/',
'https://stackoverflow.com/',
'https://www.google.com/',
'https://www.google.com/no-such-url',
'https://www.google.com:81'
];
$multiHandle = curl_multi_init();
$handles = [];
foreach ($urls as $url) {
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_NOBODY, 1);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
$handles[] = $handle;
curl_multi_add_handle($multiHandle, $handle);
}
do {
curl_multi_exec($multiHandle, $active);
curl_multi_select($multiHandle);
} while ($active);
$statusCodes = [];
foreach ($handles as $handle) {
$result = curl_getinfo($handle);
$statusCodes[$result['url']] = $result['http_code'];
}
curl_multi_close($multiHandle);
print_r($statusCodes);