-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathhook.php
34 lines (30 loc) · 850 Bytes
/
hook.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
<?php
Co::set(['hook_flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_NATIVE_CURL, ]);
//Co::set(['hook_flags' => SWOOLE_HOOK_ALL, ]);
Co\run(function () {
$n = 3;
while($n--) {
go('test');
}
});
function test() {
echo "curl init\n";
$ch = curl_init();
// $url = 'https://www.baidu.com/';
$url = "http://127.0.0.1:9801/";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $strHeader) {
//var_dump($ch, $strHeader);
return strlen($strHeader);
});
$output = curl_exec($ch);
var_dump($output);
var_dump(strlen($output));
if ($output === false) {
echo "CURL Error:" . curl_error($ch);
}
// var_dump($output);
curl_close($ch);
}