Reputation: 303
I am coding an API in PHP 7.2 to interface with a payment platform. I am doing that on a Mac (Catalina), and my project is reverse proxied by Nginx (Laravel Valet) on the Mac.
The simplest Curl requests take forever to complete. Like, 36 seconds (for only the curl_exec() function to execute), when the SAME request from the same machine takes 1.7 seconds with POSTMAN.
Any idea why that would be?
The Curl report seems fine (sanitised):
* 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/[email protected]/cert.pem
CApath: /usr/local/etc/[email protected]/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
And the request seems simple enough (and identical to the POSTMAN one):
$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);
Reading some messages on the web, I have tried to add curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($curl CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
but it doesn't change anything...
Many thanks! E.
Upvotes: 2
Views: 393
Reputation: 303
You are absolutely right. In my case, I had a “misconfigured DNS resolver(s)”. Found out by running a Valet diagnostic. Some obsolete DNS declared in my Mac network settings...
For some reason, Postman did not mind, but PHP Curl was lost.
Stupid of me though.
E.
Upvotes: 2