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


PHP curl_multi_select函数代码示例

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


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

示例1: addMembers

function addMembers($auth_code, $id, $pilots)
{
    $count = count($pilots);
    $i = 1;
    $j = 0;
    foreach ($pilots as $pilot) {
        //	echo $i."/".$count." ".$pilot->name."<br>";
        if ($j == 0) {
            $mh = curl_multi_init();
            $mhArray = [];
        }
        $mhArray[$j] = curl_multi_post_handle("https://crest-tq.eveonline.com/characters/" . $id . "/contacts/", $auth_code, (int) $pilot->character_id, $pilot->name, $_GET["standing"], $_GET["watched"], $_GET["blocked"]);
        curl_multi_add_handle($mh, $mhArray[$j]);
        if ($j == 19) {
            $j = 0;
            do {
                curl_multi_exec($mh, $running);
                curl_multi_select($mh);
            } while ($running > 0);
            curl_multi_close($mh);
        } else {
            $j = $j + 1;
        }
        //print_r( curl_post("https://crest-tq.eveonline.com/characters/".$id."/contacts/",$auth_code,(int)$pilot->character_id,$pilot->name));
        $i = $i + 1;
        flush();
    }
    do {
        curl_multi_exec($mh, $running);
        curl_multi_select($mh);
    } while ($running > 0);
    curl_multi_close($mh);
    echo $count;
}
开发者ID:Shegox,项目名称:WatchListForEvE,代码行数:34,代码来源:addCorperationMembers.php

示例2: 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

示例3: flush

 public function flush()
 {
     foreach ($this->queue as $i => $queue) {
         list($request, $response, $curl) = $queue;
         if (null === $curl) {
             $curl = $this->queue[$i][2] = static::createCurlHandle();
         }
         $this->prepare($request, $response, $curl);
         curl_multi_add_handle($this->curl, $curl);
     }
     $active = null;
     do {
         $mrc = curl_multi_exec($this->curl, $active);
     } while (CURLM_CALL_MULTI_PERFORM == $mrc);
     while ($active && CURLM_OK == $mrc) {
         if (-1 != curl_multi_select($this->curl)) {
             do {
                 $mrc = curl_multi_exec($this->curl, $active);
             } while (CURLM_CALL_MULTI_PERFORM == $mrc);
         }
     }
     foreach ($this->queue as $queue) {
         list($request, $response, $curl) = $queue;
         $response->fromString(static::getLastResponse(curl_multi_getcontent($curl)));
         curl_multi_remove_handle($this->curl, $curl);
     }
     $this->queue = array();
 }
开发者ID:kingsj,项目名称:core,代码行数:28,代码来源:MultiCurl.php

示例4: multiCurlSelect

 public function multiCurlSelect()
 {
     // TODO: Yes, very very dirty. cURL integration with event loop is required
     $timeout = 0.01;
     curl_multi_select($this->curl_mh, $timeout);
     $this->multiCurlPoll();
 }
开发者ID:futoin,项目名称:core-php-ri-invoker,代码行数:7,代码来源:SimpleCCMImpl.php

示例5: execSubrequests

 private function execSubrequests()
 {
     do {
         curl_multi_exec($this->multiDescriptor, $active);
         curl_multi_select($this->multiDescriptor);
     } while ($active > 0);
 }
开发者ID:meniam,项目名称:catalog-api,代码行数:7,代码来源:MultiRequest.php

示例6: exec

 function exec($one = null)
 {
     if (!($this->mh && $this->ch)) {
         return false;
     }
     $running = null;
     do {
         curl_multi_exec($this->mh, $running);
         curl_multi_select($this->mh);
     } while ($running > 0);
     foreach ($this->ch as $key => $value) {
         $result[$key] = curl_multi_getcontent($value);
         curl_multi_remove_handle($this->mh, $value);
         curl_close($value);
     }
     curl_multi_close($this->mh);
     $this->mh = $this->ch = null;
     if ($one) {
         $out = null;
         foreach ($result as $key => $value) {
             $out .= $value;
         }
         return $out;
     } else {
         return $result;
     }
 }
开发者ID:highestgoodlikewater,项目名称:spider-3,代码行数:27,代码来源:curl.class.php

示例7: multieFecth

 /**
  * 並列リクエストを実行します。
  * 
  * @param CurlMultiHandler $cmh
  * @return array[CurlResponse]
  */
 public static function multieFecth(CurlMultiHandler $cmh)
 {
     $mh = $cmh->getHandle();
     $active = null;
     do {
         $mrc = curl_multi_exec($mh, $active);
     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
     while ($active and $mrc == CURLM_OK) {
         if (curl_multi_select($mh) != -1) {
             do {
                 $mrc = curl_multi_exec($mh, $active);
             } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         }
     }
     $crs = array();
     foreach ($cmh->getHandlers() as $h) {
         $ch = $h->getHandle();
         $response = curl_multi_getcontent($ch);
         if ($response === false) {
             throw new CurlFetchException(curl_errno($ch), curl_error($ch));
         }
         array_push($crs, new CurlResponse($response, $ch));
         $cmh->remove($h);
         $h->close();
     }
     $cmh = null;
     return $crs;
 }
开发者ID:syamgot,项目名称:php-curl,代码行数:34,代码来源:Curl.php

示例8: __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

示例9: main

function main()
{
    $port = $_ENV['SERVERPORT'];
    $host = php_uname('n');
    $url = "http://{$host}:{$port}/hello.php";
    $ch1 = curl_init();
    $ch2 = curl_init();
    curl_setopt($ch1, CURLOPT_URL, $url);
    curl_setopt($ch1, CURLOPT_HEADER, 0);
    curl_setopt($ch1, CURLOPT_WRITEFUNCTION, 'except');
    curl_setopt($ch2, CURLOPT_URL, $url);
    curl_setopt($ch2, CURLOPT_HEADER, 0);
    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $ch1);
    curl_multi_add_handle($mh, $ch2);
    $active = null;
    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);
        }
    }
    curl_multi_close($mh);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:28,代码来源:test_curl_multi_except.php

示例10: exec

 public function exec()
 {
     $active = null;
     do {
         do {
             $status = curl_multi_exec($this->curlHandle, $active);
         } while ($status == CURLM_CALL_MULTI_PERFORM);
         if ($status != CURLM_OK) {
             break;
         }
         $response = array();
         $respond = curl_multi_info_read($this->curlHandle);
         while ($respond) {
             $callback = $this->requestMap[(string) $respond['handle']];
             $responses[$callback]['content'] = curl_multi_getcontent($respond['handle']);
             $responses[$callback]['httpcode'] = curl_getinfo($respond['handle'], CURLINFO_HTTP_CODE);
             curl_multi_remove_handle($this->curlHandle, $respond['handle']);
             curl_close($respond['handle']);
             $respond = curl_multi_info_read($this->curlHandle);
         }
         if ($active > 0) {
             curl_multi_select($this->curlHandle, 0.05);
         }
     } while ($active);
     return $responses;
 }
开发者ID:huwenshu,项目名称:dding,代码行数:26,代码来源:MultiCurl.php

示例11: consumeStream

 private function consumeStream()
 {
     $url = 'https://stream.gnip.com/accounts/' . GNIP_ACCOUNT . '/publishers/' . $this->endpoint . '/streams/track/Prod.json';
     $that = $this;
     $callback = function ($ch, $data) use($that) {
         $chunk = trim($data);
         if (!empty($chunk)) {
             $that->handleChunk($chunk);
         }
         return strlen($data);
     };
     $ch = curl_init();
     curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_ENCODING => 'gzip', CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => GNIP_USERNAME . ':' . GNIP_PASSWORD, CURLOPT_WRITEFUNCTION => $callback, CURLOPT_BUFFERSIZE => 2000, CURLOPT_LOW_SPEED_LIMIT => 1, CURLOPT_LOW_SPEED_TIME => 60));
     $running = null;
     $mh = curl_multi_init();
     curl_multi_add_handle($mh, $ch);
     // the event loop
     do {
         curl_multi_select($mh, 1);
         // wait for activity
         curl_multi_exec($mh, $running);
         // perform activity
     } while ($running > 0);
     curl_multi_remove_handle($mh, $ch);
     curl_multi_close($mh);
 }
开发者ID:wisutsak,项目名称:ElectionDesk,代码行数:26,代码来源:GnipConsumer.php

示例12: batch

 /**
  * Get the size of each of the urls in a list
  *
  * @param array $urls
  *
  * @return array
  * @throws \Exception
  */
 public function batch(array $urls)
 {
     $multi = curl_multi_init();
     $results = array();
     // Create the curl handles and add them to the multi_request
     foreach (array_values($urls) as $count => $uri) {
         $results[$uri] = array();
         ${$count} = $this->handle($uri, $results[$uri]);
         $code = curl_multi_add_handle($multi, ${$count});
         if ($code != CURLM_OK) {
             throw new \Exception("Curl handle for {$uri} could not be added");
         }
     }
     // Perform the requests
     do {
         while (($mrc = curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM) {
         }
         if ($mrc != CURLM_OK && $mrc != CURLM_CALL_MULTI_PERFORM) {
             throw new \Exception("Curl error code: {$mrc}");
         }
         if ($active && curl_multi_select($multi) === -1) {
             // Perform a usleep if a select returns -1.
             // See: https://bugs.php.net/bug.php?id=61141
             usleep(250);
         }
     } while ($active);
     // Figure out why individual requests may have failed
     foreach (array_values($urls) as $count => $uri) {
         $error = curl_error(${$count});
         if ($error) {
             $results[$uri]['failure_reason'] = $error;
         }
     }
     return $results;
 }
开发者ID:Automattic,项目名称:amp-wp,代码行数:43,代码来源:class-faster-image-b52f1a8-faster-image.php

示例13: run

 public function run()
 {
     // if sth. goes wrong with init (no requests), return false.
     if (!($mh = $this->initMultiHandle())) {
         return false;
     }
     $active = 0;
     do {
         do {
             $mrc = curl_multi_exec($mh, $active);
         } while (CURLM_CALL_MULTI_PERFORM === $mrc);
         switch ($mrc) {
             case CURLM_OK:
                 break;
             case CURLM_OUT_OF_MEMORY:
                 die('CURL out of memory.');
                 break;
             case CURLM_INTERNAL_ERROR:
                 ezcLog::getInstance()->log('CURL_INTERNAL ERROR', ezcLog::FATAL);
                 break;
         }
         // Did sth. happen? Did a handle finish?
         $moreMessages = 0;
         do {
             $this->handleMultiMessage(curl_multi_info_read($mh, $moreMessages));
         } while ($moreMessages);
         // wait for sth. to do
         if (-1 === curl_multi_select($mh)) {
             ezcLog::getInstance()->log('curl_multi_select returned -1', ezcLog::FATAL);
             $active = false;
             // break the loop
         }
     } while ($active);
     return TRUE;
 }
开发者ID:jou,项目名称:ymc-components,代码行数:35,代码来源:multi_handle.php

示例14: multihttpget

function multihttpget($urls)
{
    $mh = curl_multi_init();
    foreach ($urls as $i => $oneurl) {
        $ch[$i] = curl_init();
        curl_setopt($ch[$i], CURLOPT_URL, $oneurl);
        curl_setopt($ch[$i], CURLOPT_HEADER, 0);
        curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch[$i], CURLOPT_TIMEOUT, 100);
        $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
        curl_setopt($ch[$i], CURLOPT_USERAGENT, $useragent);
        curl_multi_add_handle($mh, $ch[$i]);
    }
    $active = null;
    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);
        }
    }
    $response = array();
    foreach ($ch as $k => $h) {
        $response[] = curl_multi_getcontent($h);
    }
    foreach ($ch as $h) {
        curl_multi_remove_handle($mh, $h);
    }
    curl_multi_close($mh);
    return $response;
}
开发者ID:superego546,项目名称:SMSGyan,代码行数:34,代码来源:indore_local.php

示例15: getResult

 public function getResult($key = NULL)
 {
     if ($key != NULL) {
         if (isset($this->responses[$key])) {
             return $this->responses[$key];
         }
         $innerSleepInt = $outerSleepInt = 1;
         while ($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM)) {
             usleep(intval($outerSleepInt));
             $outerSleepInt = intval(max(1, $outerSleepInt * $this->sleepIncrement));
             $ms = curl_multi_select($this->mc, 0);
             if ($ms > 0) {
                 do {
                     $this->execStatus = curl_multi_exec($this->mc, $this->running);
                     usleep(intval($innerSleepInt));
                     $innerSleepInt = intval(max(1, $innerSleepInt * $this->sleepIncrement));
                 } while ($this->execStatus == CURLM_CALL_MULTI_PERFORM);
                 $innerSleepInt = 1;
             }
             $this->storeResponses();
             if (isset($this->responses[$key]['data'])) {
                 return $this->responses[$key];
             }
             $runningCurrent = $this->running;
         }
         return NULL;
     }
     return FALSE;
 }
开发者ID:jamesmulryan,项目名称:A3M,代码行数:29,代码来源:EpiCurl.php


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