加了proxy后,偶尔成功,偶尔失败,失败了就会报错这个;
之前使用的是workerman:beta版本, 最近升级到rc就报错了。
感觉是TcpConnection或者AsyncTcpConnection的问题。
求大佬@walkor,指点迷津
demo.php
use Workerman\Worker;
require __DIR__.'/vendor/autoload.php';
/**
* Workerman: v5.0.0-rc.2
* http-client: v2.2.8
* revolt/event-loop:v1.0.6
* event: revolt
*
*/
$worker = new Worker();
// $worker->count = 4;
$worker->onWorkerStart = function () {
$http = new Workerman\Http\Client([
'max_conn_per_addr' => 128,
'keepalive_timeout' => 60,
'connect_timeout' => 5,
'timeout' => 30,
]);
$option = [
'method' => 'GET',
'headers' => [],
'data' => '',
'proxy' => 'http://127.0.0.1:1279',
];
$response = $http->request('http://myip.ipip.net/', $option);
echo (string) $response?->getBody().PHP_EOL;
};
Worker::runAll();
InvalidArgumentException: Invalid response string: Content-Length: 0 in /vendor/workerman/http-client/src/Request.php:339
Stack trace:
#0 /vendor/workerman/workerman/src/Connection/TcpConnection.php(674): Workerman\Http\Request->onMessage(Object(Workerman\Connection\AsyncTcpConnection), 'Content-Length:...')
#1 /vendor/workerman/workerman/src/Events/Revolt.php(147): Workerman\Connection\TcpConnection->baseRead(Resource id #75)
#2 /vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(589): Workerman\Events\Revolt::Workerman\Events\{closure}('l', Resource id #75)
#3 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#4 /vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#5 /vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#6 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#7 /vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->start()
#8 /vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#9 /vendor/workerman/http-client/src/Client.php(89): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#10 /demo.php(32): Workerman\Http\Client->request('http://myip.ipi...', Array)
#11 /vendor/workerman/workerman/src/Worker.php(2411): {closure}(Object(Workerman\Worker))
#12 /vendor/workerman/workerman/src/Worker.php(1597): Workerman\Worker->run()
#13 /vendor/workerman/workerman/src/Worker.php(1404): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker))
#14 /vendor/workerman/workerman/src/Worker.php(1384): Workerman\Worker::forkWorkersForLinux()
#15 /vendor/workerman/workerman/src/Worker.php(556): Workerman\Worker::forkWorkers()
#16 /demo.php(36): Workerman\Worker::runAll()
#17 {main}
系统:MAC/linux
Workerman: v5.0.0-rc.2
http-client: v2.2.8
event: revolt
revolt/event-loop:v1.0.6
1.TcpConnection中baseRead方法的 548行:
$buffer = @\fread($socket, self::READ_BUFFER_SIZE);
获取到的buffer偶尔会携带"Content-Length: 0" 开头
"Content-Length: 0
HTTP/1.1 200 OK
Date: Fri, 22 Nov 2024 03:36:49 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 70
Connection: close
Server: WAF
X-Edge: bj-tel
Access-Control-Allow-Headers: *
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *
X-Request-Id: d8dc96b5b696cb8f22c4f6f5b4f77c8b
X-Cache: BYPASS
Accept-Ranges: bytes
......
"
代理是其他开发者提交的,我不清楚情况,需要自己定位。
好的,我先研究
大佬,我调试到.TcpConnection中baseRead中,发现了问题,再怎么调,不会了,我该怎么继续进行?