您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman的http服务-请求-获取请求路径
发布时间:2021-12-05 14:29:50编辑:雪饮阅读()
获取请求路径
$path = $request->path();
返回请求的path部分。
实例:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('http://0.0.0.0:8484');
$worker->onMessage = function(TcpConnection $connection, Request $request)
{
$path = $request->path();
echo "\r\n";
echo "path\r\n";
var_dump($path);
echo "\r\n";
$connection->send("ok");
};
// 运行worker
Worker::runAll();
实例运行并有raw的get请求,带path的get请求,带queryString的get请求时:
[root@localhost workerman]# php -c /usr/local/php734/lib/php/php.ini start.php start
Workerman[start.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.22 PHP version:7.3.4
------------------------------------------ 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.
path
string(1) "/"
path
string(13) "/index/1.html"
path
string(13) "/index/1.html"
curl的raw的get请求、curl带path的get请求、curl带queryString的get请求:
[root@localhost ~]# curl --location --request GET 'http://192.168.43.170:8484'
ok[root@localhost ~]# curl --location --request GET 'http://192.168.43.170:8484/index/1.html'
ok[root@localhost ~]# curl --location --request GET 'http://192.168.43.170:8484/index/1.html?a=1&b=2'
ok
在这里可以总结下,这里的路径其实就是“协议://主机名或者ip(:端口,可选)”后面所跟上的以"/"分隔的参数,不包含queryString。或许总结的还不够精准,大概意思就是这样了。
关键字词:workerman,http,请求,路径
相关文章
- workerman的http服务-请求-获取请求uri
- workerman的http服务-请求-获取请求方法
- workerman的http服务-请求-获取host
- workerman的http服务-请求-获取指定上传文件
- workerman的http服务-请求-上传文件获取及http的413错
- workerman的Timer定时器类的定时器注意事项-多进程的
- workerman的Timer定时器类的定时器注意事项-定时器id
- workerman的Timer定时器类的del方法实现定时器删除
- workerman的Timer定时器类的del方法实现定时器回调中
- workerman的Timer定时器类的add方法实现只在进程中的