您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman的http服务-响应-发送header
发布时间:2021-12-06 23:26:55编辑:雪饮阅读()
发送header
同样的,发送header需要使用Workerman\Protocols\Http\Response响应类。
实例:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('http://0.0.0.0:8484');
$worker->onMessage = function(TcpConnection $connection, Request $request)
{
$response = new Response(200, [
'Content-Type' => 'text/html',
'X-Header-One' => 'Header Value'
], 'this is body');
$connection->send($response);
};
// 运行worker
Worker::runAll();
?>
实例运行:
[root@izj6c2jeancylo0ppo4vz5z workerman]# php test.php start
Workerman[test.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.22 PHP version:7.0.33
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root none http://0.0.0.0:8484 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
客户端查看到的响应头:
[root@izj6c2jeancylo0ppo4vz5z ~]# wget http://127.0.0.1:8484 -S
--2021-12-06 16:31:57-- http://127.0.0.1:8484/
Connecting to 127.0.0.1:8484... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: workerman
Content-Type: text/html
X-Header-One: Header Value
Connection: keep-alive
Content-Length: 12
Length: 12 [text/html]
Saving to: ‘index.html.6’
100%[======================================================================================================================================================================>] 12 --.-K/s in 0s
2021-12-06 16:31:57 (1.10 MB/s) - ‘index.html.6’ saved [12/12]
关键字词:workerman,http,header
相关文章
- workerman的http服务-响应-发送header - Response类初
- workerman的http服务-请求-获取请求sessionId
- workerman的http服务-请求-获取请求HTTP版本
- workerman的http服务-请求-获取请求queryString
- workerman的http服务-请求-获取请求路径
- workerman的http服务-请求-获取请求uri
- workerman的http服务-请求-获取请求方法
- workerman的http服务-请求-获取host
- workerman的http服务-请求-获取指定上传文件
- workerman的http服务-请求-上传文件获取及http的413错