Skip to content

Commit 3faadec

Browse files
authored
Create enableCoroutine.php
1 parent 3b8b120 commit 3faadec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Runtime/enableCoroutine.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
Swoole\Runtime::enableCoroutine();
3+
$http = new swoole_http_server("0.0.0.0", 9501);
4+
5+
$http->on('start', function($server){
6+
swoole_set_process_name('test_master');
7+
});
8+
9+
$http->on('request', function ($request, $response) {
10+
echo co::getuid();
11+
go(function() use ($request, $response){
12+
sleep(10); # 当调用睡眠函数时会自动切换为协程定时器调度,不会阻塞进程。
13+
$response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
14+
});
15+
});
16+
17+
$http->start();

0 commit comments

Comments
 (0)