本文整理汇总了PHP中Queue::pop方法的典型用法代码示例。如果您正苦于以下问题:PHP Queue::pop方法的具体用法?PHP Queue::pop怎么用?PHP Queue::pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::pop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pop
/**
* {@inheritdoc}
*/
public function pop()
{
return $this->exceptional(function () {
return $this->queue->pop();
});
}
示例2: start
public function start()
{
if ($this->isActive || $this->isStopped) {
return;
}
$this->isActive = true;
$this->isStarted = true;
$curlHandle = curl_multi_init();
try {
do {
// send requests from queue to CURL
if (count($this->activeRequests) < $this->connectionsLimit) {
for ($i = $this->connectionsLimit - count($this->activeRequests); $i > 0; $i--) {
$request = $this->queue->pop();
if ($request) {
$this->sendRequestToMultiCurl($curlHandle, $request);
$this->activeRequests[$request->getId()] = $request;
} else {
break;
}
}
}
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($curlHandle, $activeThreads)) {
}
// check complete requests
curl_multi_select($curlHandle, $this->requestingDelay);
while ($completeCurlInfo = curl_multi_info_read($curlHandle)) {
$completeRequestId = Request::getRequestIdByCurlHandle($completeCurlInfo['handle']);
$completeRequest = $this->activeRequests[$completeRequestId];
unset($this->activeRequests[$completeRequestId]);
curl_multi_remove_handle($curlHandle, $completeRequest->getCurlHandle());
$completeRequest->handleCurlResult();
// check if response code is 301 or 302 and follow location
$ignoreNotification = false;
$completeRequestCode = $completeRequest->getCode();
if ($completeRequestCode == 301 || $completeRequestCode == 302) {
$completeRequestOptions = $completeRequest->getCurlOptions();
if (!empty($completeRequestOptions[CURLOPT_FOLLOWLOCATION])) {
$completeRequest->_permanentlyMoved = empty($completeRequest->_permanentlyMoved) ? 1 : $completeRequest->_permanentlyMoved + 1;
$responseHeaders = $completeRequest->getResponseHeaders(true);
if ($completeRequest->_permanentlyMoved < 5 && !empty($responseHeaders['Location'])) {
// figure out whether we're dealing with an absolute or relative redirect (thanks to kmontag https://github.com/kmontag for this bugfix)
$redirectedUrl = (parse_url($responseHeaders['Location'], PHP_URL_SCHEME) === null ? $completeRequest->getBaseUrl() : '') . $responseHeaders['Location'];
$completeRequest->setUrl($redirectedUrl);
$completeRequest->reInitCurlHandle();
$this->pushRequestToQueue($completeRequest);
$ignoreNotification = true;
}
}
}
if (!$ignoreNotification) {
$this->notifyRequestComplete($completeRequest);
}
}
} while (!$this->isStopped && ($this->activeRequests || $this->queue->count()));
} catch (Exception $exception) {
}
$this->isActive = false;
if ($curlHandle && is_resource($curlHandle)) {
curl_multi_close($curlHandle);
}
if (!empty($exception)) {
throw $exception;
}
/** @noinspection PhpUndefinedMethodInspection */
$this->callbacks->onComplete($this);
}
示例3: pop
/**
* {@inheritdoc}
*/
public function pop()
{
$item = $this->queue->pop();
return unserialize(base64_decode($item));
}
示例4: king
{
// 可优化: stack1的最后一个元素可直接出栈,这样少一次入栈出栈
while (!$this->stack1->isEmpty()) {
$this->stack2->push($this->stack1->pop());
}
return $this->stack2->pop();
}
}
// 优化
// 入队时,先判断s1是否为空,如不为空,说明所有元素都在s1,此时将入队元素直接压入s1;如为空,要将s2的元素逐个“倒回”s1,再压入入队元素。
// 出队时,先判断s2是否为空,如不为空,直接弹出s2的顶元素并出队;如为空,将s1的元素逐个“倒入”s2,把最后一个元素弹出并出队
$que = new Queue();
$que->push('a');
$que->push('b');
$que->push('c');
$que->pop();
$que->pop();
$que->pop();
function king($n, $m)
{
$monkey = range(1, $n);
$i = 0;
while (count($monkey) > 1) {
$i += 1;
$head = array_shift($monkey);
if ($i % $m != 0) {
array_push($monkey, $head);
} else {
echo $head, "\n";
}
}
示例5: next
public static function next($queueName)
{
$wrapCoroutine = Queue::pop($queueName);
if ($wrapCoroutine) {
self::wrap($wrapCoroutine);
}
}