您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman的http服务-请求-获取请求uri
发布时间:2021-12-05 13:57:14编辑:雪饮阅读()
获取请求uri
$uri = $request->uri();
返回请求的uri,包括path和queryString部分。
实例:
<?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)
{
$uri = $request->uri();
echo "\r\n";
echo "uri\r\n";
var_dump($uri);
echo "\r\n";
$connection->send("ok");
};
// 运行worker
Worker::runAll();
实例运行并有curl分别直接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.
uri
string(1) "/"
uri
string(13) "/index/1.html"
uri
string(21) "/index/1.html?a=1&b=2"
curl分别直接get请求、带path的get请求、带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
关键字词: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方法实现只在进程中的
- workerman的Timer定时器类的add方法实现匿名传参定时