本文整理汇总了PHP中curl_multi_setopt函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_multi_setopt函数的具体用法?PHP curl_multi_setopt怎么用?PHP curl_multi_setopt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_multi_setopt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCurlMulti
/**
* @return resource
*/
protected function getCurlMulti()
{
if (!$this->multiHandle) {
$cmh = curl_multi_init();
if (function_exists('curl_multi_setopt')) {
// PHP 5.5
curl_multi_setopt($cmh, CURLMOPT_PIPELINING, (int) $this->usePipelining);
curl_multi_setopt($cmh, CURLMOPT_MAXCONNECTS, (int) $this->maxConnsPerHost);
}
$this->multiHandle = $cmh;
}
return $this->multiHandle;
}
示例2: 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;
}
示例3: setOptions
/**
* Set cURL option
*
* @param array $options
*
* @throws GrasshopperException
*/
public function setOptions($options)
{
foreach ($options as $key => $value) {
$res = curl_multi_setopt($this->mh, $key, $value);
if (!$res) {
throw new GrasshopperException('curl_setopt_array failed', Grasshopper::ERROR_M_SETOPTIONS);
}
}
}
示例4: __construct
/**
* Constructor.
* Initialize cURL multi handle.
* @param CoOption $options
*/
public function __construct(CoOption $options)
{
$this->mh = curl_multi_init();
$flags = (int) $options['pipeline'] + (int) $options['multiplex'] * 2;
curl_multi_setopt($this->mh, CURLMOPT_PIPELINING, $flags);
$this->options = $options;
$this->scheduler = $options['autoschedule'] ? new AutoScheduler($options, $this->mh) : new ManualScheduler($options, $this->mh);
$this->delayer = new Delayer();
}
示例5: __construct
/**
* Class Constructor, init the multi curl handler
*
*/
public function __construct()
{
$this->multi_handler = curl_multi_init();
Utils::getPHPVersion();
if (PHP_MINOR_VERSION >= 5) {
// curl_multi_setopt only for (PHP 5 >= 5.5.0) Default 10
curl_multi_setopt($this->multi_handler, CURLMOPT_MAXCONNECTS, 50);
}
}
示例6: handlerMulti
/**
* @return resource
*/
private function handlerMulti()
{
if (!$this->_pool_master) {
$this->_pool_master = curl_multi_init();
if (function_exists('curl_multi_setopt')) {
curl_multi_setopt($this->_pool_master, CURLMOPT_MAXCONNECTS, $this->simultaneousLimit);
}
}
return $this->_pool_master;
}
示例7: __construct
public function __construct($options = null)
{
$this->options = $options;
$curl_opts = null;
$this->curl_opts = $curl_opts ? $curl_opts : [];
// TODO: cURL "eventization" with libevent/libev/libuv and integration with AsyncSteps loop
$this->curl_mh = curl_multi_init();
# Missing on HHVM
if (function_exists('curl_multi_setopt')) {
curl_multi_setopt($this->curl_mh, CURLMOPT_PIPELINING, 1);
curl_multi_setopt($this->curl_mh, CURLMOPT_MAXCONNECTS, isset($curl_opts[CURLOPT_MAXCONNECTS]) ? $curl_opts[CURLOPT_MAXCONNECTS] : 8);
}
}
示例8: setOption
public function setOption($options, $value = null)
{
if (is_int($options) && $value !== null) {
curl_multi_setopt($this->_mh, $options, $value);
} elseif (is_array($options)) {
foreach ($options as $option => $value) {
$this->setOption($option, $value);
}
} else {
throw new \InvalidArgumentException('$option type must be int or array');
}
return $this;
}
示例9: curlMultiSetOpt
/**
* Set an option for the cURL multi handle
*
* @param int $option One of the CURLMOPT_* constants.
* @param mixed $value The value to be set on option.
* @return self
*/
public final function curlMultiSetOpt($option, $value)
{
curl_multi_setopt($this->curl_multi_handle, $option, $value);
return $this;
}
示例10: runMultiCurlsBlockWise
/**
* @param $curlHandles
* @throws RoutingMachineException
* @return array
*/
private function runMultiCurlsBlockWise($curlHandles)
{
//we run curl_multi only on a BLOCKSIZE so we don't generate a flood
$curlMultiHandle = curl_multi_init();
curl_multi_setopt($curlMultiHandle, CURLMOPT_PIPELINING, 1);
curl_multi_setopt($curlMultiHandle, CURLMOPT_MAXCONNECTS, self::BLOCK_SIZE);
$responses = array();
$blockCount = 0;
// count where we are in the list so we can break up the runs into smaller blocks
$blockResults = array();
// to accumulate the curl_handles for each group we'll run simultaneously
foreach ($curlHandles as $hashKey => $curlHandle) {
$blockCount++;
// add the handle to the curl_multi_handle and to our tracking "block"
curl_multi_add_handle($curlMultiHandle, $curlHandle);
$blockResults[$hashKey] = $curlHandle;
if ($blockCount % self::BLOCK_SIZE === 0 or $blockCount === count($curlHandles)) {
$running = NULL;
do {
// track the previous loop's number of handles still running so we can tell if it changes
$runningBefore = $running;
// run the block or check on the running block and get the number of sites still running in $running
curl_multi_exec($curlMultiHandle, $running);
// if the number of sites still running changed, print out a message with the number of sites that are still running.
if ($running != $runningBefore) {
//waiting for running sites to finish
}
} while ($running > 0);
//once the number still running is 0, curl_multi_ is done, so check the results
foreach ($blockResults as $hashKeyBlock => $result) {
// HTTP response code
$code = curl_getinfo($result, CURLINFO_HTTP_CODE);
// cURL error number
$curlErrno = curl_errno($result);
// cURL error message
$curlError = curl_error($result);
// output if there was an error
if ($curlError) {
throw new RoutingMachineException("OSRM cURL error: ({$curlErrno}) {$curlError}\n");
}
// fill results from our requests we get
$response = curl_multi_getcontent($result);
$responses[$hashKeyBlock] = $response;
// remove the (used) handle from the curl_multi_handle
curl_multi_remove_handle($curlMultiHandle, $result);
}
// reset the block to empty, since we've run its curl_handles
$blockResults = array();
}
}
// close the curl_multi_handle once we're done
curl_multi_close($curlMultiHandle);
return $responses;
}
示例11: download
/**
* @param Package\PackageInterface[] $packages
* @param array $pluginConfig
* @return void
*/
public function download(array $packages, array $pluginConfig)
{
$mh = curl_multi_init();
$unused = array();
$maxConns = $pluginConfig['maxConnections'];
for ($i = 0; $i < $maxConns; ++$i) {
$unused[] = curl_init();
}
/// @codeCoverageIgnoreStart
if (function_exists('curl_share_init')) {
$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
foreach ($unused as $ch) {
curl_setopt($ch, CURLOPT_SHARE, $sh);
}
}
if (function_exists('curl_multi_setopt')) {
if ($pluginConfig['pipeline']) {
curl_multi_setopt($mh, CURLMOPT_PIPELINING, true);
}
}
/// @codeCoverageIgnoreEnd
$cachedir = rtrim($this->config->get('cache-files-dir'), '\\/');
$chFpMap = array();
$running = 0;
//ref type
$remains = 0;
//ref type
$this->totalCnt = count($packages);
$this->successCnt = 0;
$this->failureCnt = 0;
$this->io->write(" Prefetch start: <comment>success: {$this->successCnt}, failure: {$this->failureCnt}, total: {$this->totalCnt}</comment>");
do {
// prepare curl resources
while ($unused && $packages) {
$package = array_pop($packages);
$filepath = $cachedir . DIRECTORY_SEPARATOR . static::getCacheKey($package);
if (file_exists($filepath)) {
++$this->successCnt;
continue;
}
$ch = array_pop($unused);
// make file resource
$fp = CurlRemoteFilesystem::createFile($filepath);
$chFpMap[(int) $ch] = compact('fp', 'filepath');
// make url
$url = $package->getDistUrl();
$request = new Aspects\HttpGetRequest(parse_url($url, PHP_URL_HOST), $url, $this->io);
$request->verbose = $pluginConfig['verbose'];
if (in_array($package->getName(), $pluginConfig['privatePackages'])) {
$request->maybePublic = false;
} else {
$request->maybePublic = preg_match('%^(?:https|git)://github\\.com%', $package->getSourceUrl());
}
$onPreDownload = Factory::getPreEvent($request);
$onPreDownload->notify();
$opts = $request->getCurlOpts();
unset($opts[CURLOPT_ENCODING]);
unset($opts[CURLOPT_USERPWD]);
curl_setopt_array($ch, $opts);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_multi_add_handle($mh, $ch);
}
// start multi download
do {
$stat = curl_multi_exec($mh, $running);
} while ($stat === CURLM_CALL_MULTI_PERFORM);
// wait for any event
do {
switch (curl_multi_select($mh, 5)) {
case -1:
usleep(10);
do {
$stat = curl_multi_exec($mh, $running);
} while ($stat === CURLM_CALL_MULTI_PERFORM);
continue 2;
case 0:
continue 2;
default:
do {
$stat = curl_multi_exec($mh, $running);
} while ($stat === CURLM_CALL_MULTI_PERFORM);
do {
if ($raised = curl_multi_info_read($mh, $remains)) {
$ch = $raised['handle'];
$errno = curl_errno($ch);
$info = curl_getinfo($ch);
curl_setopt($ch, CURLOPT_FILE, STDOUT);
$index = (int) $ch;
$fileinfo = $chFpMap[$index];
unset($chFpMap[$index]);
$fp = $fileinfo['fp'];
$filepath = $fileinfo['filepath'];
fclose($fp);
if (CURLE_OK === $errno && 200 === $info['http_code']) {
//.........这里部分代码省略.........
示例12: setMaxRequest
/**
* Max request in Asynchron query
* @param $max int default:10
* @return void
*/
public function setMaxRequest($max)
{
$this->maxRequest = $max;
// PHP 5 >= 5.5.0
if (function_exists('curl_multi_setopt')) {
curl_multi_setopt($this->mh, CURLMOPT_MAXCONNECTS, $max);
}
}
示例13: setopt
/**
* Set an option for the cURL multi handle
*
* @param integer $option
* @param mixed $value
* @return boolean
*/
public function setopt($option, $value)
{
return curl_multi_setopt($this->_mh, $option, $value);
}
示例14: curl_multi_init
<?php
$mh = curl_multi_init();
var_dump(curl_multi_setopt($mh, CURLMOPT_PIPELINING, 0));
var_dump(curl_multi_setopt($mh, -1, 0));
示例15: setOption
/**
* @since 1.0
*
* @param string $name
* @param mixed $value
*/
public function setOption($name, $value)
{
$this->options[$name] = $value;
curl_multi_setopt($this->handle, $name, $value);
}