执行多个cURL请求

时间:2010-06-29 11:20:53

标签: php mysql curl

我正在尝试按顺序执行多个curl请求,但我真的没有运气,到目前为止这是我的代码,

//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);

这个文件被调用,然后这两个请求应该一个接一个地执行,但是现在它只是不起作用。

提前Thanx!

1 个答案:

答案 0 :(得分:0)

尝试使用curl_close
尝试为两个请求使用相同的curl资源 检查是否为真,没有任何请求发送到服务器