如何使用PHP同时发送多个URL?

时间:2013-08-23 09:37:30

标签: php curl

我想同时发送不同的网址。这是我用过的代码。你能告诉我这里的错误吗?

<?php
    $data = R::find('savedata','list_name = ? order by id desc',array($i));

    foreach ( $data as $list):
        $mh = curl_multi_init(); //set up a cURL multiple execution handle
        $ch = curl_init("https://example.com/save_data.php?NUM=$list->id&MSG=$message"); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 2);           
        curl_multi_add_handle($mh, $ch); 
    endforeach; 

    curl_multi_exec($mh,);                          
    curl_multi_close($mh)
?>

1 个答案:

答案 0 :(得分:0)

谢谢大家。我已经通过我自己纠正了这个问题。我正在和你分享正确的代码,

$ mobile = R :: find('add_numbers','list_name =?order by id desc',array($ i));

foreach ($mobile as $list):
    try{
  $url = "https://example.com/save_data.php?NUM=$list->id&MSG=****";
    $ch = curl_init($url);

   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // TRUE
   curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   $results = curl_exec($ch);
     $i[]=$results;
    }