gpt4 book ai didi

php - 为什么简单的 PHP Curl https POST 请求需要 30 多秒才能从 Mac 机器上完成?

转载 作者:行者123 更新时间:2023-12-04 08:35:25 24 4
gpt4 key购买 nike

我正在用 PHP 7.2 编写 API 以与支付平台交互。我在 Mac (Catalina) 上执行此操作,我的项目由 Mac 上的 Nginx (Laravel Valet) 反向代理。
最简单的 Curl 请求需要永远完成。例如,36 秒(仅用于执行 curl_exec() 函数),当来自同一台机器的 SAME 请求使用 POSTMAN 时需要 1.7 秒。
知道为什么会这样吗?
Curl 报告似乎很好(已 sanitizer ):

*   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 解析器”。通过运行 Valet 诊断发现。在我的 Mac 网络设置中声明了一些过时的 DNS...
不知为何,Postman 并不介意,但 PHP Curl 却丢失了。
虽然我很笨。
E.

关于php - 为什么简单的 PHP Curl https POST 请求需要 30 多秒才能从 Mac 机器上完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64822359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com