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


PHP curl_multi_info_read函数代码示例

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


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

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

示例2: request

 /**
  * Make the request given the Request set and content
  *
  * @param \Yubikey\RequestCollection $requests Request collection
  * @return \Yubikey\ResponseCollection instance
  */
 public function request(\Yubikey\RequestCollection $requests)
 {
     $responses = new \Yubikey\ResponseCollection();
     $startTime = microtime(true);
     $multi = curl_multi_init();
     $curls = array();
     foreach ($requests as $index => $request) {
         $curls[$index] = curl_init();
         curl_setopt_array($curls[$index], array(CURLOPT_URL => $request->getUrl(), CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1));
         curl_multi_add_handle($multi, $curls[$index]);
     }
     do {
         while (curl_multi_exec($multi, $active) == CURLM_CALL_MULTI_PERFORM) {
         }
         while ($info = curl_multi_info_read($multi)) {
             if ($info['result'] == CURLE_OK) {
                 $return = curl_multi_getcontent($info['handle']);
                 $cinfo = curl_getinfo($info['handle']);
                 $url = parse_url($cinfo['url']);
                 $response = new \Yubikey\Response(array('host' => $url['host'], 'mt' => microtime(true) - $startTime));
                 $response->parse($return);
                 $responses->add($response);
             }
         }
     } while ($active);
     return $responses;
 }
开发者ID:enygma,项目名称:yubikey,代码行数:33,代码来源:Client.php

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

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

示例5: chk

function chk($proxies)
{
	$mc = curl_multi_init ();
	for ($thread_no = 0; $thread_no<count ($proxies); $thread_no++)
	{
		$c [$thread_no] = curl_init ();
		curl_setopt ($c [$thread_no], CURLOPT_URL, "http://google.com");
		curl_setopt ($c [$thread_no], CURLOPT_HEADER, 0);
		curl_setopt ($c [$thread_no], CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($c [$thread_no], CURLOPT_CONNECTTIMEOUT, 5);
		curl_setopt ($c [$thread_no], CURLOPT_TIMEOUT, 10);
		curl_setopt ($c [$thread_no], CURLOPT_PROXY, trim ($proxies [$thread_no]));
		curl_setopt ($c [$thread_no], CURLOPT_PROXYTYPE, 0);
		curl_multi_add_handle ($mc, $c [$thread_no]);
	}
	do 
	{
		while (($execrun = curl_multi_exec ($mc, $running)) == CURLM_CALL_MULTI_PERFORM)
		if ($execrun != CURLM_OK) break;
		while ($done = curl_multi_info_read ($mc))
		{
			$info = curl_getinfo ($done ['handle']);
			if ($info ['http_code'] == 301) 
				echo trim ($proxies [array_search ($done['handle'], $c)])."<br>\r\n";
			curl_multi_remove_handle ($mc, $done ['handle']);
		}
	} while ($running);
	curl_multi_close ($mc);
}
开发者ID:Tahongpao,项目名称:Server-local,代码行数:29,代码来源:php.php

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

示例7: executeMultiRequest

 /**
  * Executes a curl request.
  *
  * @param  resource $request
  * @return \Frlnc\Slack\Contracts\Http\Response
  */
 public function executeMultiRequest($multiRequest, $singleRequests)
 {
     $responses = [];
     $infos = [];
     $active = null;
     do {
         $status = curl_multi_exec($multiRequest, $active);
         $infos[] = curl_multi_info_read($multiRequest);
     } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
     foreach ($singleRequests as $index => $singleRequest) {
         $body = curl_multi_getcontent($singleRequest);
         curl_multi_remove_handle($multiRequest, $singleRequest);
         curl_close($singleRequest);
         $info = $infos[$index];
         $statusCode = $info['http_code'];
         $headers = $info['request_header'];
         if (function_exists('http_parse_headers')) {
             $headers = http_parse_headers($headers);
         } else {
             $header_text = substr($headers, 0, strpos($headers, "\r\n\r\n"));
             $headers = [];
             foreach (explode("\r\n", $header_text) as $i => $line) {
                 if ($i !== 0) {
                     list($key, $value) = explode(': ', $line);
                     $headers[$key] = $value;
                 }
             }
         }
         $responses[] = $this->factory->build($body, $headers, $statusCode);
     }
     curl_multi_close($multiRequest);
     return $responses;
 }
开发者ID:kapik,项目名称:alfred-slack,代码行数:39,代码来源:MultiCurlInteractor.php

示例8: _lookForCompleted

 function _lookForCompleted($execute = true)
 {
     // Get information about the handle that just finished the work.
     while ($done = curl_multi_info_read($this->mh)) {
         // Call the associated listener
         foreach ($this->transfers as $lk => $listener) {
             // Strict compare handles.
             if ($listener->getCurl() === $done['handle']) {
                 $error = null;
                 if ($done['result'] != CURLE_OK) {
                     $error = curl_error($done['handle']);
                 }
                 $listener->Call($error);
                 curl_multi_remove_handle($this->mh, $done['handle']);
                 if ($execute) {
                     curl_close($done['handle']);
                     if ($this->_done) {
                         call_user_func($this->_done, $listener->getId());
                     }
                 } else {
                     $this->queue[] = $listener;
                 }
                 unset($this->transfers[$lk]);
             }
         }
     }
 }
开发者ID:splitice,项目名称:radical-net,代码行数:27,代码来源:Multi.php

示例9: wait

 /**
  * Wait for request(s) to be completed.
  *
  * @param PromiseCore|null $targetCore
  */
 public function wait(PromiseCore $targetCore = null)
 {
     do {
         $status = curl_multi_exec($this->multiHandle, $active);
         $info = curl_multi_info_read($this->multiHandle);
         if (false !== $info) {
             $core = $this->findCoreByHandle($info['handle']);
             if (null === $core) {
                 // We have no promise for this handle. Drop it.
                 curl_multi_remove_handle($this->multiHandle, $info['handle']);
                 continue;
             }
             if (CURLE_OK === $info['result']) {
                 try {
                     $core->fulfill();
                 } catch (\Exception $e) {
                     $core->reject(new RequestException($e->getMessage(), $core->getRequest(), $e));
                 }
             } else {
                 $error = curl_error($core->getHandle());
                 $core->reject(new RequestException($error, $core->getRequest()));
             }
             $this->remove($core);
             // This is a promise we are waited for. So exiting wait().
             if ($core === $targetCore) {
                 return;
             }
         }
     } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
 }
开发者ID:jrdncchr,项目名称:merlinleads,代码行数:35,代码来源:MultiRunner.php

示例10: exec

 /**
  * Execute multi curl of this Streamer
  *
  * @return boolean
  * @throws Exception
  */
 public function exec()
 {
     if (!$this->isResource()) {
         throw new Exception("Is not a valid cURL Multi Handle resource", Exception::INVALID_MULTI_CURL);
     }
     if (empty($this->streams)) {
         throw new Exception("Pull of streams is empty", Exception::PULL_IS_EMPTY);
     }
     $running = $messages = 0;
     do {
         // executing...
         if (($error = curl_multi_exec($this->curl, $running)) != 0) {
             throw new Exception(curl_multi_strerror($error), Exception::MULTI_CURL_ERROR);
         }
         // we have some completed streams in this iteration
         do {
             if ($read = curl_multi_info_read($this->curl, $messages)) {
                 $handle = $read['handle'];
                 /** @var $stream Stream */
                 $stream = $this->streams[(int) $handle];
                 $stream->setResponse($read['result'], curl_multi_getcontent($handle));
             }
         } while ($messages);
         // in god we trust...
         usleep(1000);
     } while ($running);
     // close descriptors
     $this->closeResource();
     return $this;
 }
开发者ID:pulyavin,项目名称:streams,代码行数:36,代码来源:Streamer.php

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

示例12: run

 public function run()
 {
     do {
         $status = curl_multi_exec($this->multicurl, $active);
         $info = curl_multi_info_read($this->multicurl);
         if (false !== $info) {
             $handle = $info['handle'];
             $index = array_search($handle, $this->connections);
             $callback = $this->callbacks[$index];
             // If the handle has successfully fetched content
             if ($info['msg'] == 1 && $info['result'] == 0) {
                 if ($callback != null) {
                     $result = 0;
                     $content = curl_multi_getcontent($handle);
                     call_user_func($callback, $result, $content);
                 }
             } else {
                 if ($info["msg"] == 1) {
                     if ($callback != null) {
                         $result = $info['result'];
                         $content = '';
                         call_user_func($callback, $result, $content);
                     }
                 }
             }
         }
     } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
 }
开发者ID:creativecommons,项目名称:garmonbozia,代码行数:28,代码来源:multicurl.php

示例13: multiRequest

 /**
  * @return $this
  */
 public function multiRequest($delay = null)
 {
     /*Reset response collection with empty array*/
     $this->respCollection = array();
     $this->chMulti = curl_multi_init();
     foreach ($this->urls as $k => $v) {
         $this->cHandlers[$k] = curl_init();
         $this->options[CURLOPT_URL] = $v;
         curl_setopt_array($this->cHandlers[$k], $this->options);
         curl_multi_add_handle($this->chMulti, $this->cHandlers[$k]);
     }
     $prev = $current = null;
     do {
         curl_multi_exec($this->chMulti, $current);
         if ($current < $prev) {
             $mInfo = curl_multi_info_read($this->chMulti);
             if ($mInfo) {
                 $executed = $mInfo["handle"];
                 $info = curl_getinfo($executed);
                 $content = curl_multi_getcontent($executed);
                 if ($content) {
                     $this->respCollection[$info["url"]]['requestInfo'] = $info;
                     $this->respCollection[$info["url"]]['content'] = $content;
                 }
             }
         }
         $prev = $current;
         if ($delay) {
             usleep($delay);
         }
     } while ($current > 0);
     return $this;
 }
开发者ID:render22,项目名称:rssparser,代码行数:36,代码来源:HttpClient.php

示例14: makeRequests

 /**
  * @param $mh
  * @param array $results
  * @param array $options
  * @return int
  */
 public static function makeRequests($mh, array &$results, array $options = array())
 {
     // While we're still active, execute curl
     $active = NULL;
     do {
         // Continue to exec until curl is ready to
         // give us more data
         do {
             $mrc = curl_multi_exec($mh, $active);
         } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         // Wait for activity on any curl-connection
         curl_multi_select($mh);
         //do something with the return values
         while (($info = curl_multi_info_read($mh)) !== FALSE) {
             if ($info["result"] == CURLE_OK) {
                 $info['content'] = curl_multi_getcontent($info["handle"]);
             } else {
                 $info['error'] = curl_error($info["handle"]);
             }
             $results[strval($info["handle"])] = $info;
             curl_multi_remove_handle($mh, $info["handle"]);
         }
     } while ($active && $mrc == CURLM_OK);
     curl_multi_close($mh);
     return $mrc;
 }
开发者ID:bangkok,项目名称:CodeExample,代码行数:32,代码来源:MultiCurl.php

示例15: sendAsyncRequest

 /**
  * 异步http请求
  * @param $method
  * @param $url
  * @param array $data
  * @param int $connectTimeout
  * @param int $timeout
  * @param null $callback
  * @param null $header
  * @param string $proxy
  * @param bool $needHeader
  */
 public function sendAsyncRequest($method, $url, $data = array(), $callback = null, $header = array(), $proxy = '', $needHeader = false, $connectTimeout = 5, $timeout = 5)
 {
     if (!$this->mh) {
         $this->mh = curl_multi_init();
     }
     $ch = $this->initCurl($method, $url, $data, $connectTimeout, $timeout, $header, $proxy, $needHeader);
     curl_multi_add_handle($this->mh, $ch);
     //开始执行
     do {
         $mrc = curl_multi_exec($this->mh, $active);
     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
     while ($done = curl_multi_info_read($this->mh)) {
         $result = $done['result'];
         $ch = $done['handle'];
         if ($result === CURLE_OK) {
             //请求正常返回
             if (is_callable($callback)) {
                 $resp = curl_multi_getcontent($ch);
                 call_user_func($callback, $resp);
             }
         }
         curl_multi_remove_handle($this->mh, $ch);
         curl_close($ch);
     }
 }
开发者ID:zhxia,项目名称:nspf,代码行数:37,代码来源:HttpCurl.php


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