-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathcallback_new_obj_method.phpt
53 lines (48 loc) · 1.39 KB
/
callback_new_obj_method.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
53
--TEST--
swoole_http_server: http server callback use new object method
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
$pm = new ProcessManager;
$pm->parentFunc = function () use ($pm) {
for ($i = MAX_CONCURRENCY_LOW; $i--;) {
go(function () use ($pm) {
$cli = new Swoole\Coroutine\Http\Client('127.0.0.1', $pm->getFreePort());
for ($i = MAX_REQUESTS_LOW; $i--;) {
Assert::assert($cli->get('/'));
Assert::same($cli->statusCode, 200);
Assert::same($cli->body, 'Hello Swoole!');
}
});
}
Swoole\Event::wait();
$pm->kill();
};
$pm->childFunc = function () use ($pm) {
class TestCo
{
public function foo(Swoole\Http\Request $request, Swoole\Http\Response $response)
{
co::sleep(0.001);
$cid = go(function () use ($response) {
co::yield();
$response->end('Hello Swoole!');
});
co::resume($cid);
echo @$this->test;
}
}
$http = new Swoole\Http\Server('0.0.0.0', $pm->getFreePort(), SWOOLE_BASE);
$http->set([
'worker_num' => 1,
'log_file' => '/dev/null'
]);
$http->on('request', [new TestCo, 'foo']);
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--