E
E
Elena2016-02-08 13:38:09
PHP
Elena, 2016-02-08 13:38:09

How to speed up requests through curl?

DD!
There is a script that sends a series of requests to the same site with different data. I noticed that it takes too long, it turned out that the time from sending a request to receiving a response is about 6 seconds. I think it's too much.
the code is like this:

echo "\t\t\t\t[" . date("H:i:s d.m") . "]Send request\n";
$curl = new Curl();
$response = $curl->get($url);
echo "\t\t\t\t[" . date("H:i:s d.m") . "]Got response\n";

* the linslin/yii2-curl library is used, but it is unlikely that this is the case.
what could be the problem? The site where I send requests https://www.nic.ru. How can this matter be accelerated?
PS:
On the one hand, it is interesting how you can speed up the response from the server, and on the other hand, how you can speed up the execution of the entire task.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Matrozov, 2016-02-08
@Mear

Are you creating a new curl instance before each request? curl automatically tries to use keep-alive (maintaining a connection) and multiple requests to the same site will go faster if 2+ requests do not have connection establishment overhead. I also recommend looking at the output of the curl_getinfo command (I don’t know what it is called in yii2-curl), which will indicate what exactly and how much time the curl spends on and based on this it will be possible to draw conclusions whether it is possible to improve something there.

E
Eugene, 2016-02-08
@Nc_Soft

Use curl_multi_init

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question