没有HTTP_USER_AGENT浏览器信息 怎样获得? $worker->onConnect = function (TcpConnection $connection) { $connection->send(obCache(function ()use($connection){ ps($_SERVER);// })); };
请贴出你的完整代码
在onWebSocketConnect里获取
$worker->onWebSocketConnect = function($connection) { var_dump($_SERVER); };
<?php require __DIR__ . '/vendor/autoload.php';
use Workerman\Connection\TcpConnection; use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:6767'); $worker->name = "Websocket Proxy"; $worker->count = 4; $worker->onConnect = function (TcpConnection $connection) { //想在这个位置获取浏览器头部信息User-Agent var_dump($_SERVER); }; Worker::runAll();
$_SERVER中没有
手册不是写有不支持!
@keytehu 是对的,在onWebSocketConnect 里获取浏览器信息。onConnect 完成tcp三次握手后触发的,这时候还没有数据穿出,无法获得http头信息。onWebSocketConnect是在websocket协议握手后出发的,已经传输了http头数据。
手册 https://www.workerman.net/doc/workerman/appendices/about-websocket.html#WebSocket%E5%8D%8F%E8%AE%AE%E6%8F%A1%E6%89%8B
请贴出你的完整代码
在onWebSocketConnect里获取
<?php
require __DIR__ . '/vendor/autoload.php';
use Workerman\Connection\TcpConnection;
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:6767');
$worker->name = "Websocket Proxy";
$worker->count = 4;
$worker->onConnect = function (TcpConnection $connection) {
//想在这个位置获取浏览器头部信息User-Agent
var_dump($_SERVER);
};
Worker::runAll();
$_SERVER中没有
手册不是写有不支持!
@keytehu 是对的,在onWebSocketConnect 里获取浏览器信息。onConnect 完成tcp三次握手后触发的,这时候还没有数据穿出,无法获得http头信息。onWebSocketConnect是在websocket协议握手后出发的,已经传输了http头数据。
手册 https://www.workerman.net/doc/workerman/appendices/about-websocket.html#WebSocket%E5%8D%8F%E8%AE%AE%E6%8F%A1%E6%89%8B