E
E
Extramezz2016-02-27 11:06:03
PHP
Extramezz, 2016-02-27 11:06:03

Can curl be used multiple times?

Is it possible to do so?

$curl = curl_init();

//Назначили нужные параметры

curl_exec($curl);

//Снова назначили параметры, только другие, и снова:
curl_exec($curl);

curl_close($curl);

If so, then the key question! How to make sure that cookies received after 1 request are used in all subsequent ones. Now I save them to a file, then I load them from a file... is it possible to do without this file-mutation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-02-27
@Extramezz

It is possible and even necessary for sequential requests to the same host - curl can HTTP / 1.1 and keep-alive, respectively, too: https://habrahabr.ru/post/184302/
Cookies - still CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR. If you need only within this script and nowhere else, use the tempnam(sys_get_temp_dir(), 'some name') function to create a temporary file.
Well, or CURLOPT_COOKIE, but then parse the cookies from the last answer yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question