本文整理汇总了PHP中curl_multi_remove_handle函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_multi_remove_handle函数的具体用法?PHP curl_multi_remove_handle怎么用?PHP curl_multi_remove_handle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_multi_remove_handle函数的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;
}
示例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;
}
示例3: curlMultiRequest
/**
* Perform parallel cURL request.
*
* @param array $urls Array of URLs to make request.
* @param array $options (Optional) Array of additional cURL options.
* @return mixed Results from the request (if any).
*/
public function curlMultiRequest($urls, $options = array())
{
$ch = array();
$results = array();
$mh = curl_multi_init();
foreach ($urls as $key => $val) {
$ch[$key] = curl_init();
if ($options) {
curl_setopt_array($ch[$key], $options);
}
curl_setopt($ch[$key], CURLOPT_URL, $val);
curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($mh, $ch[$key]);
}
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
// Get content and remove handles.
foreach ($ch as $key => $val) {
$results[$key] = curl_multi_getcontent($val);
curl_multi_remove_handle($mh, $val);
}
curl_multi_close($mh);
return $results;
}
示例4: 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"]);
}
}
示例5: 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;
}
示例6: checkForClosedFilePointer
function checkForClosedFilePointer($curl_option, $description)
{
$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
$ch1 = curl_init();
$ch2 = curl_init();
$options = array(CURLOPT_RETURNTRANSFER => 1, $curl_option => $fp, CURLOPT_URL => curl_cli_server_start());
// we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
if (CURLOPT_STDERR == $curl_option) {
$options[CURLOPT_VERBOSE] = 1;
}
if (CURLOPT_INFILE == $curl_option) {
$options[CURLOPT_UPLOAD] = 1;
}
curl_setopt_array($ch1, $options);
curl_setopt_array($ch2, $options);
fclose($fp);
// <-- premature close of $fp caused a crash!
$mh = curl_multi_init();
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);
$active = 0;
do {
curl_multi_exec($mh, $active);
} while ($active > 0);
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
echo "Ok for {$description}\n";
}
示例7: 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;
}
示例8: multiCurl
/**
* Php multi curl wrapper
* @param array $urls
* @return array
*/
public function multiCurl(array $urls)
{
// array of curl handles
$handles = 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 ($urls as $k => $u) {
$handles[$k] = curl_init();
curl_setopt($handles[$k], CURLOPT_URL, $u);
curl_setopt($handles[$k], CURLOPT_HTTPHEADER, array('Accept-Language:en;q=0.8,en-US;q=0.6'));
curl_setopt($handles[$k], CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($mh, $handles[$k]);
}
// execute the handles
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
// get content and remove handles
foreach ($handles as $id => $content) {
$results[$id] = curl_multi_getcontent($content);
curl_multi_remove_handle($mh, $content);
}
// all done
curl_multi_close($mh);
return $this->removeScripts($results);
}
示例9: 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;
}
示例10: execute
/**
* Executa todos os navegadores fazendo as requisições
* @return void
*/
public function execute()
{
if ($this->countRequests() == 0) {
return false;
}
// create the multiple cURL handle
$mh = curl_multi_init();
// add the two handles
foreach ($this->Browsers as $Browser) {
$Browser->prepare();
curl_multi_add_handle($mh, $Browser->getCurlResource());
}
$active = null;
// execute the handles
// execute the handles
do {
$n = curl_multi_exec($mh, $active);
usleep(800);
} while ($active);
// close the handles
foreach ($this->Browsers as $label => $Browser) {
curl_multi_remove_handle($mh, $Browser->getCurlResource());
$this->Browsers[$label]->processResult(curl_multi_getcontent($Browser->getCurlResource()));
}
curl_multi_close($mh);
}
示例11: ping
/**
* Ping web services
*
* @param string $sitemap Full website path to sitemap
* @return array Service key with the HTTP response code as the value.
*/
public static function ping($sitemap)
{
// Main handle
$master = curl_multi_init();
// List of URLs to ping
$URLs = Kohana::config('sitemap.ping');
$handles = array();
// Create handles for each URL and add them to the main handle.
foreach ($URLs as $key => $val) {
$handles[$key] = curl_init(sprintf($val, $sitemap));
curl_setopt($handles[$key], CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($handles[$key], CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handles[$key], CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3');
curl_multi_add_handle($master, $handles[$key]);
}
do {
curl_multi_exec($master, $still_running);
} while ($still_running > 0);
$info = array();
// Build an array of the execution information.
foreach (array_keys($URLs) as $key) {
$info[$key] = curl_getinfo($handles[$key], CURLINFO_HTTP_CODE);
// Close the handles while we're here.
curl_multi_remove_handle($master, $handles[$key]);
}
// and finally close the master handle.
curl_multi_close($master);
return $info;
}
示例12: safeRemove
/**
* @param Curl $ch
*
* @throws \Exception
*/
private function safeRemove(Curl $ch)
{
$return = curl_multi_remove_handle($this->multiHandle, $ch->getHandle());
if ($return !== 0) {
throw new \Exception('Error occurred: ' . $return);
}
}
示例13: sendMultiRequests
public static function sendMultiRequests($urls)
{
$result = "";
$chs = array();
$mh = curl_multi_init();
try {
foreach ($urls as $url) {
$chs[$url] = curl_init($url);
curl_setopt_array($chs[$url], self::$curl_options);
curl_multi_add_handle($mh, $chs[$url]);
}
$running = 0;
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
} catch (Exception $e) {
print_r($e->getMessage());
} finally {
foreach ($chs as $url => $curl) {
$info = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($info == 200) {
$result = $url;
}
curl_multi_remove_handle($mh, $curl);
}
curl_multi_close($mh);
}
return $result;
}
示例14: execute
public function execute()
{
$mh = curl_multi_init();
$chs = $this->chs();
$stillRunning = 0;
$result = array();
if (function_exists('curl_multi_setopt')) {
curl_multi_setopt($mh, CURLMOPT_PIPELINING, 1);
curl_multi_setopt($mh, CURLMOPT_MAXCONNECTS, $this->maxConnectsSize());
}
foreach ($chs as $ch) {
curl_multi_add_handle($mh, $ch);
}
do {
$execReturnValue = curl_multi_exec($mh, $stillRunning);
curl_multi_select($mh);
} while ($stillRunning > 0);
foreach ($chs as $i => $ch) {
$curlError = curl_error($ch);
if ($curlError === "") {
$result[$i] = curl_multi_getcontent($ch);
} else {
throw new PubnubException("Curl error on handle {$i}: {$curlError}\n");
}
curl_multi_remove_handle($mh, $ch);
curl_close($ch);
}
curl_multi_close($mh);
$this->requests = array();
if ($execReturnValue != CURLM_OK) {
throw new PubnubException(curl_multi_strerror($execReturnValue));
}
return $result;
}
示例15: 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;
}