Executing multiple cURL queries

I try to execute several curl requests sequentially, but I'm not very lucky, here is my code so far,

//upload photo
$file= 'photo.jpg';
$args = array(
    'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);

$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);

$args_two = array(
    'message' => 'This is a test post',
);

$ch_two = curl_init();
$url_two = 'https://graph.facebook.com/me/feed?access_token='.$token;
curl_setopt($ch_two, CURLOPT_URL, $url_two);
curl_setopt($ch_two, CURLOPT_HEADER, false);
curl_setopt($ch_two, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_two, CURLOPT_POST, true);
curl_setopt($ch_two, CURLOPT_POSTFIELDS, $args_two);
$data_two = curl_exec($ch_two);

This file is called, and then two requests should be executed one by one, but now it just does not work.

Thanx in advance!

+3
source share
1 answer

Try using curl_close
Try using the same curl resource for two queries.
Verify that it is true that none of the requests are sent to the servers.

0
source

Source: https://habr.com/ru/post/1752263/


All Articles