increase Curl response speed?

Asked

Viewed 848 times

1

I am using a google API and I am testing it with the code below, but there is a huge difference in direct loading by browser and PHP, it takes a lot by PHP, there is some way to "accelerate" this?

    $this -> curl = curl_init();
    curl_setopt($this -> curl, CURLOPT_URL, ltrim($this -> queryURL() . '&q=' . urlencode($this -> query)));
    curl_setopt($this -> curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($this -> curl, CURLOPT_RETURNTRANSFER, 1);
    $this -> response = curl_exec($this -> curl);

    curl_close($this -> curl);

1 answer

0

Some more options of timeout before the curl_exec:

curl_setopt($this -> curl, CURLOPT_CONNECTTIMEOUT, 1); // espera 1 segundo para conectar

curl_setopt($this -> curl, CURLOPT_TIMEOUT, 10); // espera ateh 10 segundos no envio de comandos

Based on: https://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php

Ah, and there is the option to pass the parameters in ms: CURLOPT_CONNECTTIMEOUT_MS and CURLOPT_TIMEOUT_MS

  • Both are for optimization?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.