/** * {@inheritdoc} */ public function writeItem(array $item) { $this->queue->push($item); if (count($this->queue) >= $this->size) { $this->flush(); } }
/** * Добавляем задачу в очередь * * @param mixed $data данные запроса * @param string $correlation id сообщения * * @return Producer */ public function add($data = null, $correlation = null) { $Message = $this->_message($data, ['reply_to' => $this->_cbQueue, 'correlation_id' => $correlation ?: String::uuid()]); $this->_collerations[$Message->get('correlation_id')] = time(); $this->_Messages->push($Message); return $this; }
/** * Solve missionaries and cannibals problem. * * @return bool */ public function solve() { $initialState = new State(3, 3, 0, 0, 'left'); $initialNode = new Node($initialState, null, null); if ($initialNode->state->isGoalState()) { $this->displayNodeInfo($initialNode); return true; } $queue = new SplQueue(); $queue->push($initialNode); $explored = []; while (true) { if ($queue->isEmpty()) { return false; //nothing found } $node = $queue->pop(); $this->displayNodeInfo($node); array_push($explored, $node->state); if ($node->state->isGoalState()) { return true; } //get all action and states available $states = $node->state->getNextStates(); foreach ($states as $stateNode) { if (!$stateNode->state->isValidState()) { continue; } if (!in_array($stateNode->state, $explored)) { $queue->push($stateNode); } } } }
/** * {@inheritdoc} */ public function execute(Immediate $immediate) { if (!$this->immediates->contains($immediate)) { $this->queue->push($immediate); $this->immediates->attach($immediate); } }
/** * 压入 middleware * * @param callbale $callbale 一般为回调函数 * @return \Lime\Middleware */ public function push($callbale) { if ($callbale instanceof \Closure) { $callbale = $this->bindToThis($callbale); } $this->queue->push($callbale); return $this; }
/** * @covers Gliph\Traversal\DepthFirst::traverse */ public function testProvideQueueAsStartPoint() { extract($this->v); $queue = new \SplQueue(); $queue->push($a); $queue->push($e); $this->g->addVertex($a); $this->g->addVertex($e); DepthFirst::traverse($this->g, new DepthFirstNoOpVisitor(), $queue); }
public function testForValidValues() { $var = new \SplQueue(); $var->push(1); $var->push(2); $var->push(3); $data = new VariableWrapper(get_class($var), $var); $result = $this->inspector->get($data); $this->assertInstanceOf('Ladybug\\Plugin\\Extra\\Type\\CollectionType', $result); $this->assertCount(3, $result); }
function iterate_queue_with_mode($mode) { $x = new SplQueue(); $x->setIteratorMode($mode); $x->push(1); $x->push(2); $x->push(3); foreach ($x as $y) { var_dump($y); } var_dump(count($x)); }
/** * @coroutine * * @param string $data * @param float|int $timeout * @param bool $end * * @return \Generator * * @resolve int Number of bytes written to the file. * * @throws \Icicle\Stream\Exception\UnwritableException */ protected function send(string $data, float $timeout, bool $end = false) : \Generator { if (!$this->isWritable()) { throw new UnwritableException('The file is no longer writable.'); } if ($this->queue->isEmpty()) { $awaitable = $this->push($data); } else { $awaitable = $this->queue->top(); $awaitable = $awaitable->then(function () use($data) { return $this->push($data); }); } $this->queue->push($awaitable); if ($end) { $this->writable = false; } if ($timeout) { $awaitable = $awaitable->timeout($timeout); } $this->poll->listen(); try { $result = (yield $awaitable); } catch (\Exception $exception) { $this->close(); throw $exception; } finally { if ($end) { $this->close(); } $this->poll->done(); } return $result; }
/** * @coroutine * * @param string $data * @param float|int $timeout * @param bool $end * * @return \Generator * * @resolve int Number of bytes written to the stream. * * @throws \Icicle\Stream\Exception\UnwritableException If the stream is no longer writable. */ protected function send(string $data, float $timeout = 0, bool $end = false) : \Generator { if (!$this->isWritable()) { throw new UnwritableException('The stream is no longer writable.'); } $this->buffer->push($data); if (null !== $this->delayed && !$this->buffer->isEmpty()) { $delayed = $this->delayed; $this->delayed = null; $delayed->resolve($this->remove()); } if ($end) { if ($this->buffer->isEmpty()) { $this->free(); } else { $this->writable = false; } } if (0 !== $this->hwm && $this->buffer->getLength() > $this->hwm) { $awaitable = new Delayed($this->onCancelled = $this->onCancelled ?: function () { $this->free(); }); $this->queue->push($awaitable); if ($timeout) { $awaitable = $awaitable->timeout($timeout); } (yield $awaitable); } return strlen($data); }
/** * @param string $sql * @param callable $callback */ protected function doQuery($sql, callable $callback) { //remove from idle pool $db = array_pop($this->idle_pool); /** * @var \mysqli $mysqli */ $mysqli = $db['object']; for ($i = 0; $i < 2; $i++) { $result = $mysqli->query($sql, MYSQLI_ASYNC); if ($result === false) { if ($mysqli->errno == 2013 or $mysqli->errno == 2006) { $mysqli->close(); $r = $mysqli->connect(); if ($r === true) { continue; } } else { #echo "server exception. \n"; $this->connection_num--; $this->wait_queue->push(array('sql' => $sql, 'callback' => $callback)); return; } } break; } $task['sql'] = $sql; $task['callback'] = $callback; $task['mysql'] = $db; //join to work pool $this->work_pool[$db['socket']] = $task; }
public function push($value) { if (!$value instanceof Task) { throw new \InvalidArgumentException("TaskQueue expects instance of Task only"); } parent::push($value); }
/** * @param string $sql * @param callable $callback */ protected function doQuery($sql, callable $callback) { deQueue: //remove from idle pool $db = array_pop($this->idle_pool); /** * @var \mysqli $mysqli */ $mysqli = $db['object']; if ($this->haveSwooleAsyncMySQL) { $result = swoole_mysql_query($mysqli, $sql, array($this, 'onSQLReady')); } else { $result = $mysqli->query($sql, MYSQLI_ASYNC); } if ($result === false) { if ($mysqli->errno == 2013 or $mysqli->errno == 2006 or isset($mysqli->_errno) and $mysqli->_errno == 2006) { $mysqli->close(); unset($mysqli); $this->connection_num--; //创建连接成功 if ($this->createConnection() === 0) { goto deQueue; } } else { $this->wait_queue->push(array('sql' => $sql, 'callback' => $callback)); return; } } $task['sql'] = $sql; $task['callback'] = $callback; $task['mysql'] = $db; //join to work pool $this->work_pool[$db['socket']] = $task; }
/** * Receive a value from the channel. * * Be careful when you may receive null values: you need to change the EOF param accordingly! * * @param mixed $eof The EOF value, a channel will return this value if it has been closed without an error. * @return mixed The received value. * * @throws \Throwable Fails if the channel has been closed with an error. */ public function receive($eof = null) : Awaitable { if (!$this->buffer) { while ($this->senders && !$this->senders->isEmpty()) { $subscription = $this->senders->dequeue(); if ($subscription->active) { $subscription->resolve($subscription->data); return new Success($subscription->data); } } } elseif (!$this->buffer->isEmpty()) { while ($this->senders && !$this->senders->isEmpty()) { $subscription = $this->senders->dequeue(); if ($subscription->active) { $subscription->resolve($subscription->data); $this->buffer->push($subscription->data); } } return new Success($this->buffer->dequeue()); } if ($this->closed instanceof \Throwable) { return new Failure($this->closed); } elseif ($this->closed) { return new Success($eof); } if (!$this->receivers) { $this->receivers = new \SplQueue(); } $this->receivers->enqueue($subscription = new ChannelSubscription($eof)); return $subscription; }
/** * @param \Icicle\Postgres\Connection $connection * * @throws \Icicle\Exception\InvalidArgumentError */ private function push(Connection $connection) { if (!isset($this->connections[$connection])) { throw new InvalidArgumentError('Connection is not part of this pool'); } $this->idle->push($connection); if ($this->awaitable instanceof Delayed) { $this->awaitable->resolve($connection); } }
/** * {@inheritdoc} */ public function send(string $address, int $port, string $data) : \Generator { if (!$this->isOpen()) { throw new UnavailableException('The datagram is no longer writable.'); } $data = (string) $data; $length = strlen($data); $written = 0; $peer = Socket\makeName($address, $port); if ($this->writeQueue->isEmpty()) { if (0 === $length) { return $written; } $written = stream_socket_sendto($this->getResource(), substr($data, 0, self::MAX_PACKET_SIZE), 0, $peer); // Having difficulty finding a test to cover this scenario, but the check seems appropriate. if (false === $written || -1 === $written) { $message = 'Failed to write to datagram.'; if ($error = error_get_last()) { $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']); } throw new FailureException($message); } if ($length <= $written) { return $written; } $data = substr($data, $written); } if (null === $this->await) { $this->await = $this->createAwait($this->getResource(), $this->writeQueue); $this->await->listen(); } elseif (!$this->await->isPending()) { $this->await->listen(); } $delayed = new Delayed($this->onSendCancelled); $this->writeQueue->push([$data, $written, $peer, $delayed]); try { return (yield $delayed); } catch (Throwable $exception) { $this->free($exception); throw $exception; } }
/** * @coroutine * * Returns a coroutine that is fulfilled when the stream is ready to receive data (output buffer is not full). * * @param float|int $timeout Number of seconds until the returned promise is rejected with a TimeoutException * if the data cannot be written to the stream. Use null for no timeout. * * @return \Generator * * @resolve int Always resolves with 0. * * @throws \Icicle\Stream\Exception\UnwritableException If the stream is no longer writable. * @throws \Icicle\Stream\Exception\ClosedException If the stream has been closed. */ public function await(float $timeout = 0) : \Generator { if (!$this->isWritable()) { throw new UnwritableException('The stream is no longer writable.'); } if (null === $this->await) { $this->await = $this->createAwait($this->getResource(), $this->writeQueue); $this->await->listen($timeout); } elseif (!$this->await->isPending()) { $this->await->listen($timeout); } $delayed = new Delayed($this->onCancelled); $this->writeQueue->push(['', 0, $timeout, $delayed]); try { return (yield $delayed); } catch (Throwable $exception) { $this->free($exception); throw $exception; } }
/** * @coroutine * * @param string $data * @param bool $end * * @return \Generator * * @resolve int * * @throws \Icicle\File\Exception\FileException * @throws \Icicle\Stream\Exception\UnwritableException */ protected function send(string $data, float $timeout, bool $end = false) : \Generator { if (!$this->isWritable()) { throw new UnwritableException('The file is no longer writable.'); } $task = new Internal\FileTask('fwrite', [$data], $this->id); if ($this->queue->isEmpty()) { $awaitable = new Coroutine($this->worker->enqueue($task)); $this->queue->push($awaitable); } else { $awaitable = $this->queue->top(); $awaitable = $awaitable->then(function () use($task) { return new Coroutine($this->worker->enqueue($task)); }); } if ($end) { $this->writable = false; } if ($timeout) { $awaitable = $awaitable->timeout($timeout); } try { $written = (yield $awaitable); if ($this->append) { $this->size += $written; } else { $this->position += $written; if ($this->position > $this->size) { $this->size = $this->position; } } } catch (TaskException $exception) { $this->close(); throw new FileException('Write to the file failed.', $exception); } finally { if ($end) { $this->close(); } } return $written; }
/** * {@inheritdoc} */ public function accept(bool $autoClose = true) : \Generator { while (!$this->queue->isEmpty()) { /** @var \Icicle\Awaitable\Delayed $delayed */ $delayed = $this->queue->bottom(); (yield $delayed); // Wait for previous accept to complete. } if (!$this->isOpen()) { throw new UnavailableException('The server has been closed.'); } // Error reporting suppressed since stream_socket_accept() emits E_WARNING on client accept failure. $socket = @stream_socket_accept($this->getResource(), 0); // Timeout of 0 to be non-blocking. if ($socket) { return $this->createSocket($socket, $autoClose); } $this->queue->push($delayed = new Delayed($this->onCancelled)); $this->poll->listen(); return $this->createSocket((yield $delayed), $autoClose); }
public function send($data = null) { //锁定状态写入队列 if (!empty($data)) { $this->queue->push($data); } if ($this->reconn) { Trace::debug("*********cli {$this->fd} reconn \n"); $this->cli->connect($this->conf['ip'], $this->conf['port']); $this->reconn = false; $this->lock = true; } if ($this->queue->isEmpty()) { $this->lock = false; } elseif (!$this->lock) { $this->lock = true; $data = $this->queue->shift(); Trace::debug("*********cli {$this->fd} send " . strlen($data) . "\n==================\n" . substr($data, 0, 50) . "...\n=============="); Trace::info(sprintf("Host: %-25s %s", $this->conf['host'], strstr($data, "\n", true))); //;'Host:' . $this->conf['host'] . strstr($data, "\n", true) $this->cli->send($data); } }
/** * @coroutine * * Returns a coroutine fulfilled when there is data available to read in the internal stream buffer. Note that * this method does not consider data that may be available in the internal buffer. This method can be used to * implement functionality that uses the stream socket resource directly. * * @param float|int $timeout Number of seconds until the returned coroutine is rejected with a TimeoutException * if no data is received. Use 0 for no timeout. * * @return \Generator * * @resolve string Empty string. * * @throws \Icicle\Awaitable\Exception\TimeoutException If the operation times out. * @throws \Icicle\Stream\Exception\FailureException If the stream buffer is not empty. * @throws \Icicle\Stream\Exception\UnreadableException If the stream is no longer readable. * @throws \Icicle\Stream\Exception\ClosedException If the stream has been closed. */ public function poll(float $timeout = 0) : \Generator { while (!$this->queue->isEmpty()) { /** @var \Icicle\Awaitable\Delayed $delayed */ $delayed = $this->queue->bottom(); (yield $delayed); // Wait for previous read to complete. } if (!$this->isReadable()) { throw new UnreadableException('The stream is no longer readable.'); } if ('' !== $this->buffer) { throw new FailureException('Stream buffer is not empty. Perform another read before polling.'); } $this->queue->push($delayed = new Delayed($this->onCancelled)); $this->poll->listen($timeout); (yield $delayed); if ('' !== $this->buffer) { throw new FailureException('Data unshifted to stream buffer while polling.'); } return ''; // Resolve with empty string. }
/** * Finds source vertices in a DirectedGraph, then enqueues them. * * @param DirectedGraph $graph * @param DepthFirstVisitorInterface $visitor * * @return \SplQueue */ public static function find_sources(DirectedGraph $graph, DepthFirstVisitorInterface $visitor) { $incomings = new \SplObjectStorage(); $queue = new \SplQueue(); $graph->eachEdge(function ($edge) use(&$incomings) { if (!isset($incomings[$edge[1]])) { $incomings[$edge[1]] = new \SplObjectStorage(); } $incomings[$edge[1]]->attach($edge[0]); }); // Prime the queue with vertices that have no incoming edges. $graph->eachVertex(function ($vertex) use($queue, $incomings, $visitor) { if (!$incomings->contains($vertex)) { $queue->push($vertex); // TRUE second param indicates source vertex $visitor->onInitializeVertex($vertex, TRUE, $queue); } else { $visitor->onInitializeVertex($vertex, FALSE, $queue); } }); return $queue; }
/** * Rewind the internal collection pointer, and return the first collection. * * @return array */ public function rewind() { $this->_key = -1; unset($this->_path); $this->_path = new Praspel\Iterator\WeakStack(); unset($this->_stack); $this->_stack = new \SplStack(); $this->_stack->push(['behavior' => $this->_specification, 'state' => static::STATE_REQUIRES]); unset($this->_pop); $this->_pop = new \SplQueue(); $this->_pop->push(-1); $this->next(); return $this->current(); }
$fdatabases[5] = ['DB2', 'Proprietary', 'Server', 196.13]; $fdatabases[6] = ['SQLite', 'Open-Source', 'File', 100.85]; $fdatabases[7] = ['MS Access', 'Proprietary', 'File', 140.21]; $fdatabases[8] = ['SAP Sybase', 'Proprietary', 'Server', 81.47]; $fdatabases[9] = ['Teradata', 'Proprietary', 'Server', 75.72]; $fdatabases[10] = ['MongoDB', 'Open-Source', 'Store', 301.39]; echo "\nSPL FIXED ARRAY FOR LOOP\n"; for ($i = 0; $i < 10; $i++) { echo $fdatabases[$i][0] . "\n"; echo $fdatabases[$i][1] . "\n"; echo $fdatabases[$i][2] . "\n"; echo $fdatabases[$i][3] . "\n"; } /* SPL QUEUE */ $qoperatingsystems = new SplQueue(); $qoperatingsystems->push(array('Windows 7', 'desktop', 'NT', 56.11)); $qoperatingsystems->push(array('Windows XP', 'desktop', 'NT', 10.59)); $qoperatingsystems->push(array('Windows 8', 'desktop', 'NT', 2.88)); $qoperatingsystems->push(array('Windows 8.1', 'desktop', 'NT', 11.15)); $qoperatingsystems->push(array('Windows 10', 'desktop', 'NT', 9)); $qoperatingsystems->push(array('Windows Vista', 'desktop', 'NT', 0)); $qoperatingsystems->push(array('Mac OS X 11', 'desktop', 'Unix', 2.66)); $qoperatingsystems->push(array('Mac OS X 10', 'desktop', 'Unix', 2.45)); $qoperatingsystems->push(array('Linux Mint', 'desktop', 'Linux', 0)); $qoperatingsystems->push(array('Linux Debian', 'desktop', 'Linux', 0)); $qoperatingsystems->push(array('Android', 'mobile', 'Linux', 48.12)); $qoperatingsystems->push(array('iOS', 'mobile', 'Unix', 34.71)); echo "\nSPL QUEUE ARRAY FOR LOOP: FIFO\n"; $qoperatingsystems->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO); for ($qoperatingsystems->rewind(); $qoperatingsystems->valid(); $qoperatingsystems->next()) { echo $qoperatingsystems->current()[0] . "\n";
/** * Converts a function accepting a callback ($emitter) that invokes the callback when an event is emitted into an * observable that emits the arguments passed to the callback function each time the callback function would be * invoked. * * @param callable<(mixed ...$args)> $emitter Function accepting a callback that periodically emits events. * @param int $index Position of callback function in emitter function argument list. * @param mixed ...$args Other arguments to pass to emitter function. * * @return \Icicle\Observable\Observable */ function observe(callable $emitter, int $index = 0, ...$args) : Observable { return new Emitter(function (callable $emit) use($emitter, $index, $args) : \Generator { $queue = new \SplQueue(); /** @var \Icicle\Awaitable\Delayed $delayed */ $callback = function (...$args) use(&$delayed, $queue) { if (null !== $delayed) { $delayed->resolve($args); $delayed = null; } else { $queue->push($args); } }; if (count($args) < $index) { throw new InvalidArgumentError('Too few arguments given to function.'); } array_splice($args, $index, 0, [$callback]); $emitter(...$args); while (true) { if ($queue->isEmpty()) { $delayed = new Delayed(); yield from $emit($delayed); } else { yield from $emit($queue->shift()); } } }); }
/** * @param Notification $notification */ public function add(Notification $notification) { $this->queue->push($notification); }
<?php $queue = new SplQueue(); $queue->push(1); $queue->push(2); $queue->push(4); $queue->push(3); $queue->setIteratorMode(SplQueue::IT_MODE_DELETE); foreach ($queue as $k => $v) { printf("%s => %s\n", $k, $v); }
/** * Push in queue * * @param JobInterface $command * @return $this */ public function push(JobInterface $command) { $this->jobs->push($command); return $this; }
public function fire($job, $message) { $this->warnings = array(); $commit = $message['commit']; $hostType = $message['hostType']; $siteId = $message['siteId']; $dc = new DC($siteId); $staticDir = $dc->get(DC::STATIC_DIR); if (isset($message['type']) && $message['type'] == self::TYPE_PULL_REQUEST) { $id = $message['id']; $this->type = self::TYPE_PULL_REQUEST; $this->pr = new PullRequestDeploy($siteId); $this->prDeployInfo = $this->pr->get($id); $root = (new SystemConfig())->get(SystemConfig::WORK_ROOT_FIELD) . '/' . $siteId . '/pull_requests'; $commitPath = "{$root}/commit/{$commit}"; } else { $this->type = self::TYPE_NORMAL_DEPLOY; $this->dfManger = new DeployInfo($siteId); $id = $message['id']; $this->deployInfo = $this->dfManger->get($id); $root = (new SystemConfig())->get(SystemConfig::WORK_ROOT_FIELD) . '/' . $siteId . '/commit'; $commitPath = "{$root}/{$commit}"; } $LOCAL_STATIC_DIR = "{$commitPath}/{$staticDir}"; $LOCAL_DIR = $commitPath; $remoteUser = $dc->get(DC::REMOTE_USER); $remoteOwner = $dc->get(DC::REMOTE_OWNER); $RSYNC_EXCLUDE = "{$commitPath}/" . $dc->get(DC::RSYNC_EXCLUDE); $REMOTE_STATIC_DIR = $dc->get(DC::REMOTE_STATIC_DIR); $REMOTE_DIR = $dc->get(DC::REMOTE_APP_DIR); $staticScript = ScriptCommand::complie($dc->get(DC::DEPLOY_STATIC_SCRIPT), $siteId); $webScript = ScriptCommand::complie($dc->get(DC::DEPLOY_WEB_SCRIPT), $siteId); $this->updateStatus('Deploying'); Log::info("\n---------------------------\njob id : {$job->getJobId()} start "); Log::info("commit deploy: {$commit}"); //本地同步锁,不能在同一个commit下同步 $redis = app('redis')->connection(); $commitLock = new \Eleme\Rlock\Lock($redis, JobLock::buildLock($commitPath), array('timeout' => 600000, 'blocking' => false)); if (!$commitLock->acquire()) { Log::info("Job : {$job->getJobId()} Release"); $job->release(30); } $rsyLock = NULL; try { $hosts = (new SiteHost($siteId, $hostType, SiteHost::STATIC_HOST))->getList(); $staticHosts = new SplQueue(); foreach ($hosts as $h) { $staticHosts->push($h); } $hosts = (new SiteHost($siteId, $hostType, SiteHost::WEB_HOST))->getList(); $webHosts = new SplQueue(); foreach ($hosts as $h) { $webHosts->push($h); } /***************************************** * * 执行静态文件同步 * *****************************************/ //执行同步前本地命令 $this->processCommands($staticScript['before']['handle']); while (!$staticHosts->isEmpty()) { $host = $staticHosts->shift(); $rsyLock = new \Eleme\Rlock\Lock($redis, JobLock::rsyLock($host['hostip']), array('timeout' => 600000, 'blocking' => false)); if ($rsyLock->acquire()) { try { $HOST_NAME = $host['hostname']; //执行同步前每次都执行的本地命令 $this->processCommands($staticScript['before']['local']); //执行同步前每次都执行的远端命令 $this->processCommands($staticScript['before']['remote'], $HOST_NAME); Log::info("deploying static files to {$HOST_NAME}."); (new Process($this->remoteProcess($HOST_NAME, "sudo mkdir -p {$REMOTE_STATIC_DIR}")))->mustRun(); (new Process($this->remoteProcess($HOST_NAME, "sudo chown {$remoteUser} -R {$REMOTE_STATIC_DIR}")))->mustRun(); (new Process("rsync -az --progress --force --delay-updates --exclude-from={$RSYNC_EXCLUDE} {$LOCAL_STATIC_DIR}/ {$HOST_NAME}:{$REMOTE_STATIC_DIR}/", $commitPath))->setTimeout(600)->mustRun(); (new Process($this->remoteProcess($HOST_NAME, "sudo chown {$remoteOwner} -R {$REMOTE_STATIC_DIR}")))->mustRun(); //执行同步后每次都执行的本地命令 $this->processCommands($staticScript['after']['local']); //执行同步后每次都执行的远端命令 $this->processCommands($staticScript['after']['remote'], $HOST_NAME); $rsyLock->release(); } catch (Exception $e) { $rsyLock->release(); throw $e; } } else { // 正在同步,重新放回队列 $staticHosts->push($host); } } //执行同步后本地命令 $this->processCommands($staticScript['after']['handle']); /***************************************** * * 执行WEB应用同步 * *****************************************/ //执行同步前本地命令 $this->processCommands($webScript['before']['handle']); while (!$webHosts->isEmpty()) { $host = $webHosts->shift(); $rsyLock = new \Eleme\Rlock\Lock($redis, JobLock::rsyLock($host['hostip']), array('timeout' => 600000, 'blocking' => false)); if ($rsyLock->acquire()) { try { $HOST_NAME = $host['hostname']; //执行同步前每次都执行的本地命令 $this->processCommands($webScript['before']['local']); //执行同步前每次都执行的远端命令 $this->processCommands($webScript['before']['remote'], $HOST_NAME); Log::info("deploying web apps to {$HOST_NAME}."); (new Process($this->remoteProcess($HOST_NAME, "sudo mkdir -p {$REMOTE_DIR}")))->mustRun(); (new Process($this->remoteProcess($HOST_NAME, "sudo chown {$remoteUser} -R {$REMOTE_DIR}")))->mustRun(); (new Process("rsync -azq --progress --force --delete --delay-updates --exclude-from={$RSYNC_EXCLUDE} {$LOCAL_DIR}/ {$HOST_NAME}:{$REMOTE_DIR}/", $commitPath))->setTimeout(600)->mustRun(); (new Process($this->remoteProcess($HOST_NAME, "sudo chown {$remoteOwner} -R {$REMOTE_DIR}")))->mustRun(); //执行同步后每次都执行的本地命令 $this->processCommands($webScript['after']['local']); //执行同步后每次都执行的远端命令 $this->processCommands($webScript['after']['remote'], $HOST_NAME); $rsyLock->release(); } catch (Exception $e) { $rsyLock->release(); throw $e; } } else { $webHosts->push($host); } } //执行同步后本地命令 $this->processCommands($webScript['after']['handle']); $errMsg = ''; foreach ($this->warnings as $w) { $errMsg .= "{$w}\n"; } $errMsg = empty($errMsg) ? null : $errMsg; $this->updateStatus('Deploy Success', $errMsg); Log::info($job->getJobId() . " finish"); } catch (Exception $e) { //if ($rsyLock != null) $rsyLock->release(); $this->updateStatus('Error', "file : " . $e->getFile() . "\nline : " . $e->getLine() . "\n Error Msg : " . $e->getMessage()); Log::error($e->getMessage()); Log::info($job->getJobId() . " Error Finish\n---------------------------"); } $commitLock->release(); $job->delete(); }
<?php $q = new SplQueue(); $q->push(1); $q->push(2); $q->push(3); echo $q->pop() . PHP_EOL; print_r($q); // vim600:ts=4 st=4 foldmethod=marker foldmarker=<<<,>>> // vim600:syn=php commentstring=//%s