您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman的http服务-请求-获取请求方法
发布时间:2021-12-05 13:56:35编辑:雪饮阅读()
获取请求方法
$method = $request->method();
返回值可能是GET、POST、PUT、DELETE、OPTIONS、HEAD中的一个。
实例:
<?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');
//设置上传包大小为100M,字节即byte,1kb=1024byte,1m=1024kb
TcpConnection::$defaultMaxPackageSize=100*1024*1024;
$worker->onMessage = function(TcpConnection $connection, Request $request)
{
$method = $request->method();
echo "\r\n";
echo "method:\r\n";
var_dump($method);
echo "\r\n";
$connection->send("ok");
};
// 运行worker
Worker::runAll();
实例运行并分别有post和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.
method:
string(4) "POST"
method:
string(3) "GET"
curl发送post请求与get请求:
[root@localhost ~]# curl --location --request POST 'http://192.168.43.170:8484' --data ''
ok[root@localhost ~]# curl --location --request GET 'http://192.168.43.170:8484'
ok
关键字词: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方法实现匿名传参定时
- workerman的Timer定时器类的add方法实现定时器中销毁