-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowrequest.php
More file actions
71 lines (56 loc) · 1.38 KB
/
showrequest.php
File metadata and controls
71 lines (56 loc) · 1.38 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
class SnowRequest {
const NUM_REQUESTS = 3;
protected $task = array();
public function __construct($urls) {
$this->initUrls($urls);
$this->initCurl();
}
private function initUrls($urls) {
foreach (array_unique($urls) as $url) {
$this->task[$url] = array();
}
}
private function initCurl() {
return true;
}
public function processAllUrls() {
foreach (array_keys($this->task) as $url) {
print($url);
$mess = "\n\t" . implode("\n\t", self::processUrl($url)) . "\n";
print($mess);
}
}
public static function processUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$count = 0;
$redirect = false;
$curUrl = $url;
$result = array();
do {
curl_setopt($ch, CURLOPT_URL, $curUrl);
$html = curl_exec($ch);
$info = curl_getinfo($ch);
if ($redirect = self::isRedirect($info)) {
$result[] = $info['http_code'] . ' ' . $info['redirect_url'];
$curUrl = $info['redirect_url'];
}
else {
$result[] = $info['http_code'];
}
} while ($redirect && $count++ < self::NUM_REQUESTS);
curl_close($ch);
return $result;
}
private static function isRedirect($info) {
return $info['http_code'] == 301 || $info['http_code'] == 302;
}
}
$urls = array(
'https://google.com',
'https://ya.ru',
);
$sr = new SnowRequest($urls);
$sr->processAllUrls();