forked from swoole/swoole-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.phpt
52 lines (49 loc) · 1.19 KB
/
get.phpt
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
--TEST--
Test of swoole_http_client->get
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
function start_swoole_http_server() {
$code = <<<'DOC'
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set(array(
'worker_num' => 2,
));
$http->on('request', function ($request, swoole_http_response $response) {
$route = $request->server['request_uri'];
if($route == '/info'){
$response->end($request->header['user-agent']);
return;
}else{
$cli = new swoole_http_client('127.0.0.1', 9501);
$cli->set(array(
'timeout' => 0.3,
));
$cli->setHeaders(array('User-Agent' => "swoole"));
$cli->on('close', function($cli)use($response){
});
$cli->on('error', function($cli) use ($response){
echo "error";
$response->end("error");
});
$cli->get('/info', function($cli)use( $response){
$response->end($cli->body."\n");
});
}
});
$http->start();
DOC;
swoole_php_fork($code);
}
sleep(1); //wait the release of port 9501
start_swoole_http_server();
sleep(1);
echo file_get_contents("http://127.0.0.1:9501/");
?>
Done
--EXPECTREGEX--
swoole
Done.*
--CLEAN--