为什么简单的PHP Curl https POST请求在Mac机器上需要30秒以上才能完成



我正在用PHP 7.2编写一个API,以与支付平台对接。我在Mac(Catalina(上做这件事,我的项目由Mac上的Nginx(Laravel Valet(反向代理。

最简单的Curl请求需要很长时间才能完成。例如,36秒(仅用于执行curl_exec((函数(,而来自同一台机器的SAME请求使用POSTMAN需要1.7秒。

知道为什么会这样吗?

Curl报告似乎很好(经过消毒(:

*   Trying xxx.0.xxx.78:443...
* Connected to api.paymentplatform.com (xxx.0.xxx.78) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl@1.1/cert.pem
CApath: /usr/local/etc/openssl@1.1/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=California; L=San Jose; O=Destination, Inc.; OU=Destination Production; CN=api.sandbox.paypal.com
*  start date: Jul 27 00:00:00 2020 GMT
*  expire date: Aug  1 12:00:00 2022 GMT
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
*  SSL certificate verify ok.
* Server auth using Basic with user 'AfqL2fMLLxXhm6ZNQRtQmqGJKReMEL5jXJMVO4uqpadvIfx6YEAccIxxxxxxxxx-xxxxxxxxxxx'
> POST /v1/oauth2/token HTTP/1.1
Host: api.paymentplatform.com
Authorization: Basic QWZxTDJmTUxMeFhobTZaTlFSdFFtcUdKS1JlTUVMNWpYSk1WTzR1cXBhZHZJZng2WUVBY2NJRm1fY2pob0RZTno2ZS1hV3B3QnhnWU1STlM6RUpSUzNrc1hhSFcybEhIZDAxMVh1Wkt4Y3ZqdXhzYS0wbmlhTWZ6Mzluaxxxxxxxxxxxxxxxxxxxxxxxxx=
Accept-Encoding: deflate, gzip, br, zstd
Accept-Language: en_US
Accept: application/json
Content-Length: 29
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 29 out of 29 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Content-Length: 701
< Content-Type: application/json
< Date: Fri, 13 Nov 2020 13:45:13 GMT
< Destination-Debug-Id: b6e1e8dda1785
< X-Destination-Token-Service: IAAS
< 
* Connection #0 to host api.paymentplatform.com left intact

这个请求似乎很简单(与POSTMAN的请求相同(:

$curl = curl_init();
$header = array(
'Accept-Language: en_US',
'Accept: application/json'
);
curl_setopt_array($curl, array(
CURLOPT_URL             => VB_P['API_URL'].'/v1/oauth2/token',
CURLOPT_RETURNTRANSFER  => true,
//CURLOPT_HEADER          => 'Accept: application/json',
CURLOPT_HTTPHEADER      => $header,
//CURLOPT_HEADER        => 'Accept-Language: en_US',
CURLOPT_ENCODING        => "",
CURLOPT_MAXREDIRS       => 10,
CURLOPT_TIMEOUT         => 0,
CURLOPT_FOLLOWLOCATION  => true,
CURLOPT_HTTP_VERSION    => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST   => "POST",
CURLOPT_POSTFIELDS      => "grant_type=client_credentials",
CURLOPT_USERPWD         => VB_P['CLIENT_ID'].':'.VB_P['CLIENT_SECRET']
));
if (VB_SERV_NAME == 'local') {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
}
$time_start = microtime(true);
$response_json = curl_exec($curl);
$time_end = microtime(true);

读到网上的一些消息,我尝试添加curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($curl CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );但它不会改变任何事情。。。

非常感谢!E.

你说得绝对正确。在我的案例中,我有一个"错误配置的DNS解析程序"。通过运行代客泊车诊断发现。在我的Mac网络设置中声明了一些过时的DNS。。。

出于某种原因,Postman并不介意,但PHP Curl丢失了。

不过我太笨了。

E。

最新更新