您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman的http服务-响应-重定向
发布时间:2021-12-06 23:36:18编辑:雪饮阅读()
重定向
实例:
<?php
use Workerman\Worker;
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($connection, $request)
{
if ($request->path() === '/test_location') {
$connection->send(new Response(200, [], '<h1>重定向到了test_location页面!</h1>'));
}
else{
$location = '/test_location';
$response = new Response(302, ['Location' => $location]);
$connection->send($response);
}
};
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 ~]# elinks http://127.0.0.1:8484 --dump
重定向到了test_location页面!
关键字词:workerman,http,响应,重定向
相关文章
- workerman的http服务-响应-重定向 - 发送文件(实现文件
- workerman的http服务-响应-重定向 - 发送cookie
- workerman的http服务-响应-快捷响应
- workerman的http服务-响应-更改状态码
- workerman的http服务-响应-更改状态码 - Response类初
- workerman的http服务-响应-发送header
- workerman的http服务-响应-发送header - Response类初
- workerman的http服务-请求-获取请求sessionId
- workerman的http服务-请求-获取请求HTTP版本
- workerman的http服务-请求-获取请求queryString