当前位置: 首页>>代码示例>>PHP>>正文


PHP curl_multi_getcontent函数代码示例

本文整理汇总了PHP中curl_multi_getcontent函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_multi_getcontent函数的具体用法?PHP curl_multi_getcontent怎么用?PHP curl_multi_getcontent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了curl_multi_getcontent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getMultiContents

/**
 * http://techblog.yahoo.co.jp/architecture/api1_curl_multi/
 * 複数URLのコンテンツ、及び通信ステータスを一括取得する。
 * サンプル:
 *   $urls = array( "http://〜", "http://〜", "http://〜" );
 *   $results = getMultiContents($urls);
 *   print_r($results);
 */
function getMultiContents($url_list)
{
    // マルチハンドルの用意
    $mh = curl_multi_init();
    // URLをキーとして、複数のCurlハンドルを入れて保持する配列
    $ch_list = array();
    // Curlハンドルの用意と、マルチハンドルへの登録
    foreach ($url_list as $url) {
        $ch_list[$url] = curl_init($url);
        curl_setopt($ch_list[$url], CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch_list[$url], CURLOPT_TIMEOUT, 1);
        // タイムアウト秒数を指定
        curl_setopt($ch_list[$url], CURLOPT_SSL_VERIFYPEER, false);
        curl_multi_add_handle($mh, $ch_list[$url]);
    }
    // 一括で通信実行、全て終わるのを待つ
    $running = null;
    do {
        curl_multi_exec($mh, $running);
    } while ($running);
    // 実行結果の取得
    foreach ($url_list as $url) {
        // ステータスとコンテンツ内容の取得
        $results[$url] = curl_getinfo($ch_list[$url]);
        $results[$url]["content"] = curl_multi_getcontent($ch_list[$url]);
        // Curlハンドルの後始末
        curl_multi_remove_handle($mh, $ch_list[$url]);
        curl_close($ch_list[$url]);
    }
    // マルチハンドルの後始末
    curl_multi_close($mh);
    // 結果返却
    return $results;
}
开发者ID:gaogao-9,项目名称:status.gochiusa.club,代码行数:42,代码来源:getMultiCotents.php

示例2: exec

 public function exec()
 {
     $mh = curl_multi_init();
     foreach ($this->url_list as $i => $url) {
         $conn[$i] = curl_init($url);
         curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($conn[$i], CURLOPT_HEADER, 0);
         curl_setopt($conn[$i], CURLOPT_NOBODY, 0);
         curl_setopt($conn[$i], CURLOPT_FOLLOWLOCATION, 0);
         curl_setopt($conn[$i], CURLOPT_TIMEOUT, 30);
         curl_multi_add_handle($mh, $conn[$i]);
     }
     $active = FALSE;
     do {
         $mrc = curl_multi_exec($mh, $active);
     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
     while ($active && $mrc == CURLM_OK) {
         //if(curl_multi_select($mh) != -1){
         do {
             $mrc = curl_multi_exec($mh, $active);
         } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         //}
     }
     $result = array();
     foreach ($this->url_list as $i => $url) {
         $result[$i] = curl_multi_getcontent($conn[$i]);
         curl_close($conn[$i]);
         curl_multi_remove_handle($mh, $conn[$i]);
     }
     curl_multi_close($mh);
     return $result;
 }
开发者ID:xujunjiepk,项目名称:YOF,代码行数:32,代码来源:L_Multi_Curl.class.php

示例3: curl_multi_request

 function curl_multi_request($query_arr, $data, $method = 'POST')
 {
     $ch = curl_multi_init();
     $count = count($query_arr);
     $ch_arr = array();
     for ($i = 0; $i < $count; $i++) {
         $query_string = $query_arr[$i];
         $ch_arr[$i] = curl_init($query_string);
         curl_setopt($ch_arr[$i], CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch_arr[$i], CURLOPT_POST, 1);
         curl_setopt($ch_arr[$i], CURLOPT_POSTFIELDS, $data);
         // post 提交方式
         curl_multi_add_handle($ch, $ch_arr[$i]);
     }
     $running = null;
     do {
         curl_multi_exec($ch, $running);
     } while ($running > 0);
     for ($i = 0; $i < $count; $i++) {
         $results[$i] = curl_multi_getcontent($ch_arr[$i]);
         curl_multi_remove_handle($ch, $ch_arr[$i]);
     }
     curl_multi_close($ch);
     return $results;
 }
开发者ID:ice-gyx,项目名称:transfer,代码行数:25,代码来源:Http.php

示例4: execute

 public function execute()
 {
     $mh = curl_multi_init();
     $conn = [];
     foreach ($this->getUrls() as $k => $url) {
         $this->setOption(CURLOPT_URL, $url);
         $ch = curl_init();
         curl_setopt_array($ch, $this->getOptions());
         $conn[$k] = $ch;
         curl_multi_add_handle($mh, $conn[$k]);
     }
     $active = false;
     do {
         $mrc = curl_multi_exec($mh, $active);
     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
     while ($active && $mrc == CURLM_OK) {
         if (curl_multi_select($mh) != -1) {
             do {
                 $mrc = curl_multi_exec($mh, $active);
             } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         }
     }
     $res = [];
     foreach ($this->getUrls() as $k => $url) {
         $res[$k] = curl_multi_getcontent($conn[$k]);
         curl_close($conn[$k]);
         curl_multi_remove_handle($mh, $conn[$k]);
     }
     curl_multi_close($mh);
     return $res;
 }
开发者ID:xiaojiays,项目名称:curl,代码行数:31,代码来源:Curl.php

示例5: multiFetchRequest

 /**
  * Performs multiple (array of RemoteContentRequest) requests and fills in the responses
  * in the $request objects
  *
  * @param Array of RemoteContentRequest's $requests
  * @return $requests
  */
 public function multiFetchRequest(array $requests)
 {
     $mh = curl_multi_init();
     foreach ($requests as $request) {
         $request->handle = $this->initCurlHandle($request->getUrl());
         // Set this so the multihandler will return data
         curl_setopt($request->handle, CURLOPT_RETURNTRANSFER, 1);
         $this->setHeaders($request);
         curl_multi_add_handle($mh, $request->handle);
     }
     $running = null;
     do {
         curl_multi_exec($mh, $running);
     } while ($running > 0);
     foreach ($requests as $request) {
         // Execute the request
         $content = curl_multi_getcontent($request->handle);
         $this->parseResult($request, $content);
         curl_multi_remove_handle($mh, $request->handle);
         unset($request->handle);
     }
     curl_multi_close($mh);
     unset($mh);
     return $requests;
 }
开发者ID:rysk92,项目名称:opOpenSocialPlugin,代码行数:32,代码来源:BasicRemoteContentFetcher.php

示例6: multi_get_urls

 public static function multi_get_urls(&$urls)
 {
     if (count($urls) <= 0) {
         return false;
     }
     $harr = array();
     //handle array
     foreach ($urls as $k => $v) {
         $h = curl_init();
         curl_setopt($h, CURLOPT_URL, $v['url']);
         curl_setopt($h, CURLOPT_HEADER, 0);
         curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
         array_push($harr, $h);
     }
     $mh = curl_multi_init();
     foreach ($harr as $k => $v) {
         curl_multi_add_handle($mh, $v);
     }
     $running = null;
     do {
         curl_multi_exec($mh, $running);
     } while ($running > 0);
     // get the result and save it in the result ARRAY
     foreach ($harr as $k => $h) {
         $urls[$k]['data'] = curl_multi_getcontent($h);
     }
     // close all the connections
     foreach ($harr as $k => $v) {
         curl_multi_remove_handle($mh, $v);
     }
     curl_multi_close($mh);
     return true;
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:33,代码来源:curl.php

示例7: sendInternalRequests

 /**
  * {@inheritdoc}
  */
 protected function sendInternalRequests(array $internalRequests, $success, $error)
 {
     $curlMulti = curl_multi_init();
     $contexts = array();
     foreach ($internalRequests as $internalRequest) {
         $contexts[] = array('curl' => $curl = $this->createCurl($internalRequest), 'request' => $internalRequest);
         curl_multi_add_handle($curlMulti, $curl);
     }
     do {
         do {
             $exec = curl_multi_exec($curlMulti, $running);
         } while ($exec === CURLM_CALL_MULTI_PERFORM);
         while ($done = curl_multi_info_read($curlMulti)) {
             $curl = $done['handle'];
             $internalRequest = $this->resolveInternalRequest($curl, $contexts);
             try {
                 $response = $this->createResponse($curl, curl_multi_getcontent($curl), $internalRequest);
                 $response = $response->withParameter('request', $internalRequest);
                 call_user_func($success, $response);
             } catch (HttpAdapterException $e) {
                 $e->setRequest($internalRequest);
                 call_user_func($error, $e);
             }
             curl_multi_remove_handle($curlMulti, $curl);
             curl_close($curl);
         }
     } while ($running);
     curl_multi_close($curlMulti);
 }
开发者ID:czifumasa,项目名称:Inzynierka6,代码行数:32,代码来源:CurlHttpAdapter.php

示例8: multiGet

 /**
  * @param string[] $urls
  * @return string[]
  */
 public function multiGet(array $urls)
 {
     $curlHandlers = [];
     $multiHandler = curl_multi_init();
     foreach ($urls as $url) {
         $currentHandler = curl_init($url);
         $curlHandlers[$url] = $currentHandler;
         curl_setopt($currentHandler, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($currentHandler, CURLOPT_CONNECTTIMEOUT, self::TIMEOUT);
         curl_multi_add_handle($multiHandler, $currentHandler);
     }
     $isStillRunning = null;
     do {
         curl_multi_exec($multiHandler, $isStillRunning);
         sleep(self::LOAD_WAIT_TIME);
     } while ($isStillRunning);
     $results = [];
     // get content and remove handles
     foreach ($urls as $url) {
         $currentHandler = $curlHandlers[$url];
         $results[$url] = curl_multi_getcontent($currentHandler);
         curl_multi_remove_handle($multiHandler, $currentHandler);
     }
     // all done
     curl_multi_close($multiHandler);
     return $results;
 }
开发者ID:nazar256,项目名称:cli-example-tag-counter,代码行数:31,代码来源:WebClient.php

示例9: multi_request

 function multi_request($urls)
 {
     $curly = array();
     $result = array();
     $mh = curl_multi_init();
     foreach ($urls as $id => $url) {
         $curly[$id] = curl_init();
         curl_setopt($curly[$id], CURLOPT_URL, $url);
         curl_setopt($curly[$id], CURLOPT_HEADER, 0);
         curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curly[$id], CURLOPT_TIMEOUT, 30);
         curl_setopt($curly[$id], CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($curly[$id], CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($curly[$id], CURLOPT_SSL_VERIFYHOST, 0);
         curl_multi_add_handle($mh, $curly[$id]);
     }
     $running = null;
     do {
         curl_multi_exec($mh, $running);
     } while ($running > 0);
     foreach ($curly as $id => $c) {
         $result[$id] = curl_multi_getcontent($c);
         curl_multi_remove_handle($mh, $c);
     }
     curl_multi_close($mh);
     return $result;
 }
开发者ID:xepan,项目名称:epanservices,代码行数:27,代码来源:Initiator.php

示例10: __call

 /** Execute request or get its response
  * @param string request identifier
  * @param array array(string $url) for executing request, array() for getting response
  * @return mixed
  */
 function __call($name, array $args)
 {
     if ($args) {
         // execute request
         list($url) = $args;
         $curl = curl_init($url);
         $this->curl[$name] = $curl;
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         $return = curl_multi_add_handle($this->multi, $curl);
         while (curl_multi_exec($this->multi, $running) == CURLM_CALL_MULTI_PERFORM) {
         }
         return $return;
     }
     // get response
     if (!isset($this->curl[$name])) {
         // wrong identifier
         return false;
     }
     $curl = $this->curl[$name];
     while (!isset($this->done[(int) $curl])) {
         curl_multi_select($this->multi, $this->timeout);
         while (curl_multi_exec($this->multi, $running) == CURLM_CALL_MULTI_PERFORM) {
         }
         while ($info = curl_multi_info_read($this->multi)) {
             if ($info["msg"] == CURLMSG_DONE) {
                 $this->done[(int) $info["handle"]] = true;
             }
         }
     }
     return curl_multi_getcontent($curl);
 }
开发者ID:Topthinking,项目名称:php-async,代码行数:36,代码来源:CurlAsync.php

示例11: mult_post

function mult_post($connomains)
{
    $mh = curl_multi_init();
    foreach ($connomains as $i => $url) {
        $postData = "------WebKitFormBoundaryy9zMscQCwUGxoejM\r\n";
        $postData .= "Content-Disposition: form-data; name=\"urllink\"\r\n\r\n";
        $postData .= $url . "\r\n";
        $postData .= "------WebKitFormBoundaryy9zMscQCwUGxoejM\r\n";
        $postData .= "Content-Disposition: form-data; name=\"url-2txt\"\r\n\r\n\r\n\r\n";
        $postData .= "------WebKitFormBoundaryy9zMscQCwUGxoejM--\r\n";
        $post_url = "http://deeplearning.cs.toronto.edu//api/url.php";
        $header = array("Host: deeplearning.cs.toronto.edu", "Content-Length: " . strlen($postData), 'X-Requested-With: XMLHttpRequest', 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryy9zMscQCwUGxoejM', 'Accept-Language: zh-CN,zh;q=0.8', 'X-Requested-With: XMLHttpRequest', 'X-Requested-With: XMLHttpRequest');
        $conn[$i] = curl_init('http://deeplearning.cs.toronto.edu//api/url.php');
        // $res= curl_setopt ($mh, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($conn[$i], CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($conn[$i], CURLOPT_HEADER, 0);
        curl_setopt($conn[$i], CURLOPT_POST, 1);
        curl_setopt($conn[$i], CURLOPT_POSTFIELDS, $postData);
        curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($conn[$i], CURLOPT_HTTPHEADER, $header);
        curl_multi_add_handle($mh, $conn[$i]);
    }
    do {
        $n = curl_multi_exec($mh, $active);
    } while ($active);
    foreach ($connomains as $i => $urlwhole) {
        $pattern = '#Sentence:</h4><ul><li>(.*)</li></ul><br/><h4>#';
        $res[$i] = getPatternResult($pattern, curl_multi_getcontent($conn[$i]));
        curl_close($conn[$i]);
    }
    // print_r($res);
    return $res;
}
开发者ID:bajian,项目名称:js-web-skills,代码行数:34,代码来源:pic2text+mult.php

示例12: checkForCompletedRequests

 private function checkForCompletedRequests()
 {
     do {
         $mrc = curl_multi_exec($this->multi_handle, $active);
     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
     while ($active && $mrc == CURLM_OK) {
         if (curl_multi_select($this->multi_handle) != -1) {
             do {
                 $mrc = curl_multi_exec($this->multi_handle, $active);
             } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         } else {
             return;
         }
     }
     // Now grab the information about the completed requests
     while ($info = curl_multi_info_read($this->multi_handle)) {
         $ch = $info['handle'];
         $ch_array_key = (int) $ch;
         if (!isset($this->outstanding_requests[$ch_array_key])) {
             die("Error - handle wasn't found in requests: '{$ch}' in " . print_r($this->outstanding_requests, true));
         }
         $request = $this->outstanding_requests[$ch_array_key];
         $url = $request['url'];
         $content = curl_multi_getcontent($ch);
         $callback = $request['callback'];
         $user_data = $request['user_data'];
         call_user_func($callback, $content, $url, $ch, $user_data);
         unset($this->outstanding_requests[$ch_array_key]);
         curl_multi_remove_handle($this->multi_handle, $ch);
     }
 }
开发者ID:kubinpe5,项目名称:youtube-reranking,代码行数:31,代码来源:ParallelCurl.php

示例13: ApiFindMymovies

 public function ApiFindMymovies()
 {
     $message = "je suis vide";
     $mymovies = $this->em->getRepository('FilmBundle:Moviesfavorite')->FindMymovies($this->user->getid());
     $ch = array();
     $responses = array();
     $mh = curl_multi_init();
     foreach ($mymovies as $key => $value) {
         $ch[$key] = curl_init("http://api.themoviedb.org/3/movie/" . $value->getIdmovies() . "?api_key=c7eb74475a1e3d62a7ab838d184bf0a7&language=fr");
         curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
         curl_multi_add_handle($mh, $ch[$key]);
     }
     $running = null;
     do {
         curl_multi_exec($mh, $running);
     } while ($running);
     foreach ($mymovies as $key => $value) {
         $data = curl_multi_getcontent($ch[$key]);
         $responses[$key] = $data;
     }
     curl_multi_close($mh);
     if (is_array($responses)) {
         return $responses;
     } else {
         return $message;
     }
 }
开发者ID:Jrbebel,项目名称:GestionFilm,代码行数:27,代码来源:ServiceFilmotheque.php

示例14: longurl_api

 protected function longurl_api($url, $options = array())
 {
     if (empty($options['format'])) {
         $options['format'] = 'php';
     }
     $options['user-agent'] = empty($options['user-agent']) ? "LongURL-PHP-Client-Library/0.1" : $options['user-agent'];
     // construct the query
     $queries = array();
     if (is_array($options)) {
         $queries = array_merge($queries, $options);
     }
     $query = http_build_query($queries);
     $url .= '?' . $query;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_USERAGENT, $options['user-agent']);
     curl_exec($ch);
     $longurl_return = array();
     $longurl_return['headers'] = curl_getinfo($ch);
     $content = curl_multi_getcontent($ch);
     if ($options['format'] == 'php') {
         $longurl_return['content'] = unserialize($content);
     } else {
         $longurl_return['content'] = $content;
     }
     return $longurl_return;
 }
开发者ID:sillygwailo,项目名称:LongURL,代码行数:28,代码来源:LongURL.php

示例15: multiCurlPoll

 public function multiCurlPoll()
 {
     $curl_mh = $this->curl_mh;
     do {
         $mrc = curl_multi_exec($curl_mh, $still_running);
         if ($mrc == CURLM_OK) {
             $info = curl_multi_info_read($curl_mh);
             if ($info && isset($this->curl_cb[(int) $info['handle']])) {
                 $as = $this->curl_cb[(int) $info['handle']];
                 $curl = $info['handle'];
                 unset($this->curl_cb[(int) $curl]);
                 $as->_futoin_response = curl_multi_getcontent($curl);
                 $as->success($curl, $info);
                 curl_multi_remove_handle($this->curl_mh, $curl);
             }
         }
     } while ($mrc === CURLM_CALL_MULTI_PERFORM);
     if ($this->curl_event !== null) {
         \FutoIn\RI\AsyncTool::cancelCall($this->curl_event);
         $this->curl_event = null;
     }
     if ($this->curl_cb) {
         $this->curl_event = \FutoIn\RI\AsyncTool::callLater([$this, "multiCurlSelect"]);
     }
 }
开发者ID:futoin,项目名称:core-php-ri-invoker,代码行数:25,代码来源:SimpleCCMImpl.php


注:本文中的curl_multi_getcontent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。