php中的multicurl不能在Linux服务器上运行

时间:2015-03-10 10:28:47

标签: php linux curl

我正在尝试在multicurl上执行linux server,我在获取所需输入方面遇到问题,但相同的代码仍在本地Wamp执行。

下面是我写的multicurl函数和我传递给它的array数据。

INPUT数组传递:

$first="http://www.dailymotion.com/cdn/H264-1280x720/video/x2j0gos.mp4?auth=1426064982-2562-grdf1d1z-f6b64b422eb5af322ebb7f8f4815adda";

$second="http://www.dailymotion.com/cdn/H264-1280x720/video/x2j0i9t.mp4?auth=1426137719-2562-zeubydw0-85a25e35daf6297a2110cdb3f866bb82";

$third="http://www.dailymotion.com/cdn/H264-848x480/video/x2j0i9t.mp4?auth=1426145999-2562-m9bdtntj-94fb745e495a2009e67dc0f96c431b3f";

$data = array($first,$second,$third);
$r= multiRequest($data);
echo '<pre>';
print_r($r);
echo "<br>";

multicurl功能

function multiRequest($data, $options = array()) {

  // array of curl handles
  $curly = array();
  // data to be returned
  $result = array();

  // multi handle
  $mh = curl_multi_init();

  // loop through $data and create curl handles
  // then add them to the multi-handle
  foreach ($data as $id => $d) {

    $curly[$id] = curl_init();

    $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
    curl_setopt($curly[$id], CURLOPT_URL,$url);
    curl_setopt($curly[$id], CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curly[$id], CURLOPT_HEADER,0);
    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curly[$id], CURLOPT_AUTOREFERER, 1);
    curl_setopt($curly[$id], CURLOPT_FOLLOWLOCATION, 1);
//    curl_setopt($curly[$id], CURLOPT_MAXREDIRS, 5);
    curl_setopt($curly[$id], CURLOPT_TIMEOUT, 30);
/* 
    // post?
    if (is_array($d)) {
      if (!empty($d['post'])) {
        curl_setopt($curly[$id], CURLOPT_POST,       1);
        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
      }
    }

    // extra options?
    if (!empty($options)) {
      curl_setopt_array($curly[$id], $options);
    }*/

    curl_multi_add_handle($mh, $curly[$id]);
  }

  // execute the handles
  $running = null;
  do {
   $status=curl_multi_exec($mh, $running);
  } while($status === CURLM_CALL_MULTI_PERFORM || $running);


  // get content and remove handles
  foreach($curly as $id => $c) {
    //$result[$id] = curl_multi_getcontent($c); 
    $result[$id] = curl_getinfo($c, CURLINFO_EFFECTIVE_URL);
    curl_multi_remove_handle($mh, $c);
  }

  // all done
  curl_multi_close($mh);

  return $result;
}

有人可以指出错误是什么,或者我是否必须向服务器添加任何内容?

0 个答案:

没有答案