代码如下:
<?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:9898');
$worker->onWorkerStart = function()
{
global $http_client;
$http_client = new Workerman\Http\Client();
};
$worker->onMessage = function(TcpConnection $connection, Request $request)
{
global $http_client;
$http_client->get('https://www.baidu.com', function (\Psr\Http\Message\ResponseInterface $response) use($connection){
$message = $response->getBody()->__toString();
$connection->send($message);
}, function ($exception) {
echo $exception;
});
};
// 运行worker
Worker::runAll();
百度返回的内容是
location.replace(location.href.replace("https://","http://"));
导致浏览器不停的刷新,然后再次返回相同的内容,再次刷新。。。具体为什么百度返回的是刷新,可能和某个http头有关系。懂了,谢谢群主,没注意看返回代码。。.