- 新增 Swoole 协程运行示例文件 co.php - 添加错误常量引用示例文件 const-ref.php - 创建 Swoole HTTP 服务器示例文件 http.php - 实现基本的协程运行功能 - 集成 HTTP 服务器请求处理逻辑 - 添加异常处理和响应状态管理pull/1/head
parent
7519c3c523
commit
2d0baeaea9
3 changed files with 31 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||||||
|
<?php |
||||||
|
function main() |
||||||
|
{ |
||||||
|
parse_str('hello=s', "hello"); |
||||||
|
} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
Swoole\Coroutine\run(function () { |
||||||
|
sleep(1); |
||||||
|
}); |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
<?php |
||||||
|
function main() |
||||||
|
{ |
||||||
|
$http = new Swoole\Http\Server('127.0.0.1', 9501); |
||||||
|
|
||||||
|
|
||||||
|
$http->on('request', function ($request, $response) { |
||||||
|
try { |
||||||
|
$response->header('Content-Type', 'text/plain'); |
||||||
|
$response->end('Hello World'); |
||||||
|
} catch (Exception $e) { |
||||||
|
$response->status(500); |
||||||
|
$response->end('error: ' . $e->getMessage()); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
$http->start(); |
||||||
|
} |
||||||
Loading…
Reference in new issue