3

I am using google-php-api for authentication.

this takes most of the time just under 6 seconds, $client->authenticate($code);

this takes most of the time about 3 seconds, $token = $client->getAccessToken();

this takes most of the time just under 6 seconds too. $client->$data = $client->verifyIdToken($tokens->id_token)

Any idea why, or is it normal?

kak3n
  • 71
  • 1
  • 7

3 Answers3

4

Forceing ipv4 hepled

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
kak3n
  • 71
  • 1
  • 7
  • Great! Response time improved from ~6 seconds to ~0.5 seconds – jap1968 Nov 19 '16 at 23:08
  • In newer version it should be possible to set it by some function so you don't have manually add the code. – kak3n Nov 21 '16 at 15:57
  • THanks! If someone encounters issues like: "Use of undefined constant CURLOPT_IPRESOLVE" You need to install php-curl and restart your webserver. For example, on debian with apache2: `apt-get update; apt-get install php-curl; systemctl restart apache2;` Should be fixed now. – ezekiel87 Jun 18 '23 at 13:45
1

For the ones using with Guzzle, supporting @kak3n answer :

$http = new GuzzleHttp\Client([
    'timeout'           => 3,
    'force_ip_resolve'  => 'v4'
]);

$client->setHttpClient($http);

realy worked for me. Before it was around 64 seconds and now only a couple seconds.

Funny part is time out. It takes as long as time out ??? Try it with a longer value see for your self ;)

ergunkocak
  • 3,334
  • 1
  • 32
  • 31
0

The same for me. The problem was cURL that generate the error: Hostname was NOT found in DNS cache.

Someone here Curl Hostname was NOT found in DNS cache error say that the issue is the cURL version

--------EDIT--------

I added to /etc/resolv.conf

nameserver 127.0.0.1

first it was only

nameserver 8.8.8.8

...and all is very fast

Community
  • 1
  • 1
Gianluca Demarinis
  • 1,964
  • 2
  • 15
  • 21
  • Yes @gianluca-demarinis its seems the issue is caused by [Curl Hostname was NOT found in DNS cache](http://stackoverflow.com/questions/27093467/curl-hostname-was-not-found-in-dns-cache-error) but adding nameserver 127.0.0.1 to /etc/resolv.conf, btw I found that the conf is created dynamicaly so after restart it wont be there read [this](http://askubuntu.com/questions/130452/how-do-i-add-a-dns-server-via-resolv-conf). – kak3n May 25 '16 at 15:45
  • it wont be there only if you have installed Network Manager – Gianluca Demarinis May 26 '16 at 10:16