Yurunsoft / Guzzle-Swoole

让基于 Guzzle 的项目完美无缝兼容 Swoole 协程,支持:Guzzle、Elasticsearch client——来自宇润 PHP 全家桶
MIT License
161 stars 21 forks source link

'verify' => false对https无效 #2

Closed millken closed 6 years ago

millken commented 6 years ago

swoole 4.0.3,php 7.2.8

            $response = $client->request('GET', 'https://ecs-buy.aliyun.com/api/ecsPrice/describePrice.jsonp', [
                'verify' => false,
            ]);

默认是没有问题的

Yurunsoft commented 6 years ago

我这边测试了,'verify' => false没有问题 当verify为false时,不会验证证书,怎么会无效呢

millken commented 6 years ago

嗯,我也测试了下,发现正常使用没用

<?php

require dirname(__DIR__).'/vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

go(function () {
    $handler = new GuzzleSwooleHandler();
    $stack = HandlerStack::create($handler);
    $client = new Client(['handler' => $stack]);

    $response = $client->request('GET', 'https://ecs-buy.aliyun.com/api/ecsPrice/describePrice.jsonp', [
        'query' => [
            'callback' => 'angular.callbacks._6',
        '_timestamp' => time(),
        'data' => '{"orderType":"instance-buy","regionId":"cn-hangzhou-dg-a01","commodity":{"zoneId":"random","instanceType":"ecs.xn4.small","ioOptimized":true,"networkType":"vpc","internetChargeType":"PayByBandwidth","internetMaxBandwidthOut":1,"imageType":"public","systemDisk":{"category":"cloud_efficiency","size":"40"},"dataDisks":null,"priceUnit":"Month","periodType":"Monthly","period":1,"amount":1,"maxAmount":1,"autoRenew":false}}',
    ],
        'headers' => [
            'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
            'Referer' => 'https://ecs-buy.aliyun.com/simple/',
            'Accept-Encoding' => 'deflate, br',
            'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
        ],
        'verify' => false,
    ]);
    var_dump($response->getStatusCode(), $response->getBody()->__toString(), $response->getHeaders());
});

但是我是创建了自定义进程,然后在swoole_timer里跑的,这样返回-2 的状态码。 具体我再调试下,谢谢!

Yurunsoft commented 6 years ago

https://wiki.swoole.com/wiki/page/726.html 在约定的时间内服务器未返回响应,请求超时,statusCode将设置为-2 应该是超时了,你调试下看看先

millken commented 6 years ago

刚测试发现,加了'timeout' => 1.0,就返回正常了,不加的话就会有问题。

Yurunsoft commented 6 years ago

了解了,晚点加个默认timeout

Yurunsoft commented 6 years ago

最新版中已经修复这个问题,guzzletimeout默认为0是不限制超时时间,现在已经支持了