function sendtoirc($nick, $window, $input) { if ($input[0] == '/') { $input = substr($input, 1); list($command, $remainder) = explode(' ', $input); $command = strtoupper($command); if ($command == 'ME') { $input = ":{$nick} PRIVMSG {$window} :ACTION{$remainder}"; } elseif ($command == 'QUERY') { $parts = explode(',', $remainder); foreach ($parts as $part) { add_window(strtolower($part)); } return; } elseif ($command == 'CLOSE') { $parts = explode(',', $remainder); foreach ($parts as $part) { // del_window(strtolower($part)); } return; } else { $input = ":{$nick} " . $input; } } else { $input = ":{$nick} PRIVMSG {$window} :{$input}"; } if (!mysql_query("INSERT INTO outgoing (nickname, data) VALUES ('{$nick}', '{$input}')")) { print mysql_error(); } queue($window, $input); }
/** * POST | This handles the registration with validation. * * @return mixed */ public function storeRegistrationForm() { $inputs = request()->get(); $validator = new RegistrationValidator(); $validation = $validator->validate($inputs); if (count($validation)) { session()->set('input', $inputs); return redirect()->to(url()->previous())->withError(RegistrationValidator::toHtml($validation)); } $token = bin2hex(random_bytes(100)); $connection = db()->connection(); try { $connection->begin(); $user = new User(); $success = $user->create(['email' => $inputs['email'], 'password' => security()->hash($inputs['password']), 'token' => $token]); if ($success === false) { throw new Exception('It seems we can\'t create an account, ' . 'please check your access credentials!'); } queue(\Components\Queue\Email::class, ['function' => 'registeredSender', 'template' => 'emails.registered-inlined', 'to' => $inputs['email'], 'url' => route('activateUser', ['token' => $token]), 'subject' => 'You are now registered, activation is required.']); $connection->commit(); } catch (TransactionFailed $e) { $connection->rollback(); throw $e; } catch (Exception $e) { $connection->rollback(); throw $e; } return redirect()->to(route('showLoginForm'))->withSuccess(lang()->get('responses/register.creation_success')); }
/** * Do connect to the low level driver */ function connect() { if (!$this->_connection) { $this->_connection = queue()->connect(); } return $this->_connection; }
public function then(callable $onFulfilled = null, callable $onRejected = null) { // If there's no onRejected callback then just return self. if (!$onRejected) { return $this; } $queue = queue(); $reason = $this->reason; $p = new Promise([$queue, 'run']); $queue->add(static function () use($p, $reason, $onRejected) { if ($p->getState() === self::PENDING) { try { // Return a resolved promise if onRejected does not throw. $p->resolve($onRejected($reason)); } catch (\Throwable $e) { // onRejected threw, so return a rejected promise. $p->reject($e); } catch (\Exception $e) { // onRejected threw, so return a rejected promise. $p->reject($e); } } }); return $p; }
public function done(callable $onFulfilled = null, callable $onRejected = null) { if (null === $onFulfilled) { return; } queue()->enqueue(function () use($onFulfilled) { $result = $onFulfilled($this->value); if ($result instanceof ExtendedPromiseInterface) { $result->done(); } }); }
/** * Adds a function to run in the task queue when it is next `run()` and returns * a promise that is fulfilled or rejected with the result. * * @param callable $task Task function to run. * * @return PromiseInterface */ function task(callable $task) { $queue = queue(); $promise = new Promise([$queue, 'run']); $queue->add(function () use($task, $promise) { try { $promise->resolve($task()); } catch (\Exception $e) { $promise->reject($e); } }); return $promise; }
public function done(callable $onFulfilled = null, callable $onRejected = null) { queue()->enqueue(function () use($onRejected) { if (null === $onRejected) { throw UnhandledRejectionException::resolve($this->reason); } $result = $onRejected($this->reason); if ($result instanceof self) { throw UnhandledRejectionException::resolve($result->reason); } if ($result instanceof ExtendedPromiseInterface) { $result->done(); } }); }
public function then(callable $onFulfilled = null, callable $onRejected = null) { // Return itself if there is no onFulfilled function. if (!$onFulfilled) { return $this; } $queue = queue(); $p = new Promise([$queue, 'run']); $value = $this->value; $queue->add(static function () use($p, $value, $onFulfilled) { if ($p->getState() === self::PENDING) { try { $p->resolve($onFulfilled($value)); } catch (\Exception $e) { $p->reject($e); } } }); return $p; }
public function test_queue_redis() { $GLOBALS['conf']['wrapper_queue']['driver'] = 'redis'; $queue = queue(); $this->assertInternalType('object', $queue); $this->assertSame($queue, _class('wrapper_queue')); /* $queue->connect(); $this->assertTrue($queue->is_ready()); $key = 'mytestkey'; $val = 'mytestval'; if (!empty($queue->get($key))) { $this->assertEquals($queue->del($key), 1); } $this->assertEmpty($queue->get($key)); $this->assertTrue($queue->set($key, $val)); $this->assertEquals($queue->get($key), $val); $this->assertEquals($queue->del($key), 1); $this->assertEmpty($queue->get($key)); */ }
<?php require __DIR__ . '/_init.php'; queue()->listen($conf['prefix'] . $conf['queue'], function ($item) { var_dump($item); });
<?php require __DIR__ . '/_init.php'; foreach (range(1, 1000) as $i) { echo $i . PHP_EOL; queue()->add($conf['prefix'] . $conf['queue'], 'hello ' . $i); sleep(1); }
function email($template, $receiver, $data = []) { return queue()->create('mail:send', ['user' => $receiver, 'template' => $template, 'data' => $data]); }
require_once JNEWSPATH_ADMIN . 'controllers' . DS . 'subscribers.jnews.php'; require_once JNEWSPATH_ADMIN . 'views' . DS . 'subscribers.jnews.html.php'; subscribers($action, $task, $userid, $listId, $cid); break; case 'mailing': require_once JNEWSPATH_ADMIN . 'controllers' . DS . 'mailings.jnews.php'; require_once JNEWSPATH_ADMIN . 'views' . DS . 'mailings.jnews.html.php'; mailing($action, $task, $listId, $listType, $mailingId, $message); break; case 'statistics': require_once JNEWSPATH_ADMIN . 'controllers' . DS . 'statistics.jnews.php'; statistics($listId, $listType, $mailingId, $message, $task, $action); break; case 'queue': require_once JNEWSPATH_ADMIN . 'views' . DS . 'queue.jnews.html.php'; queue($action, $task, $listId, $mailingId, $lists = '', $cid); break; case 'configuration': require_once JNEWSPATH_ADMIN . 'views' . DS . 'config.jnews.html.php'; if ($GLOBALS[JNEWS . 'integration'] == '0' or $GLOBALS[JNEWS . 'cb_integration'] == '0') { $xf = new jNews_Config(); if (jnews::checkCB()) { $xf->loadConfig(); } } configuration($action, $task); break; case 'update': update($action, $task); break; case 'about':
/** * Send copies, mostly for debug and more control on what is going on */ function _send_copies($params = []) { if (!$params) { return false; } $copy_to = []; foreach ((array) $this->SEND_ALL_COPY_TO as $mail_to) { $copy_to[$mail_to] = $mail_to; } if ($email_to === $this->ADMIN_EMAIL) { foreach ((array) $this->SEND_ADMIN_COPY_TO as $mail_to) { $copy_to[$mail_to] = $mail_to; } } else { foreach ((array) $this->SEND_USER_COPY_TO as $mail_to) { $copy_to[$mail_to] = $mail_to; } } $orig_to_mail = strtolower(trim($params['to_mail'])); $orig_subj = $params['subj']; $params['subj'] = '[AUTO-COPY] ' . $params['subj']; foreach ((array) $copy_to as $mail_to) { $mail_to = trim($mail_to); if (!$mail_to || strtolower($mail_to) == $orig_to_mail) { continue; } $params['to_mail'] = $mail_to; if ($this->ASYNC_SEND) { queue()->add($this->QUEUE_NAME, json_encode($params)); } else { common()->send_mail((array) $params); } } return true; }
while (!feof($irc)) { set_time_limit(60); $r = fgets($irc, 512); if ($r) { print "< " . $r; $msg = irc_split_message($r); extract($msg); if ($command == 'PING') { fputs($irc, ":{$NICKNAME} PONG :{$message}\n"); } elseif ($dest and strtolower($dest) != strtolower(format_nick($origin)) and strtolower($origin) != $ircserver and $dest != 'AUTH' and $command != 'QUIT') { if (strtolower($dest) != strtolower($NICKNAME)) { queue($dest, $r); } else { queue(format_nick($origin), $r); } } else { queue('Status', $r); } } $r = get_outgoing(); foreach ($r as $row) { fputs($irc, $row['data'] . "\n"); print "> " . $row['data'] . "\n"; } usleep(50000); } } else { //FIXME -- shutdown web client with QUIT in queue } queue('Status', 'Connection closed', 'quit');
private function waitIfPending() { if ($this->state !== self::PENDING) { return; } elseif ($this->waitFn) { $this->invokeWaitFn(); } elseif ($this->waitList) { $this->invokeWaitList(); } else { // If there's not wait function, then reject the promise. $this->reject('Cannot wait on a promise that has ' . 'no internal wait function. You must provide a wait ' . 'function when constructing the promise to be able to ' . 'wait on a promise.'); } queue()->run(); if ($this->state === self::PENDING) { $this->reject('Invoking the wait callback did not resolve the promise'); } }
/** * We will send email to: * - order(s) (order.user.email, order.user.fullName) * - orderUser(s) (orderUser.user.email, orderUser.user.fullName) * - user(s) (user.email, user.fullName) * ... * with prepared: * - subject * - content * - sender email * - sender name * ... * and possible attachment(s): * - estimate(s) (order.estimate_url, orderUser.order.estimate_url) * - bills(s) (order.bill_url, orderUser.order.bill_url) * - voucher(s) (order.voucher_url, orderUser.order.voucher_url) * ... */ public function postRequestSendAction(MailRecord $mail) { $recipients = new Collection($this->post('recipients')); $attachments = new Collection($this->post('attachments')); $template = $this->post('mail'); $recipients->each(function ($recipient) use($attachments, $template, $mail) { $data = []; /** * Handle fetches. */ $order = null; if ($recipient['type'] == 'user') { $user = (new Users())->where('id', $recipient['id'])->one(); $receiver = new User($user); $data['fetch']['user'][Users::class] = $user->id; } else { if ($recipient['type'] == 'orderUser') { $orderUser = (new OrdersUsers())->where('id', $recipient['id']); $receiver = new User($orderUser->one()->user); $data['fetch']['orderUser'][OrdersUsers::class] = $orderUser->id; $data['fetch']['order'][Orders::class] = $orderUser->order_id; $data['fetch']['offer'][Offers::class] = $orderUser->order->offer_id; $data['fetch']['user'][Users::class] = $orderUser->user_id; $order = $orderUser->order; } else { if ($recipient['type'] == 'order') { $order = (new Orders())->where('id', $recipient['id'])->one(); $receiver = new User($order->user); $data['fetch']['order'][Orders::class] = $order->id; $data['fetch']['user'][Users::class] = $order->user_id; $data['fetch']['offer'][Offers::class] = $order->offer_id; } } } /** * Handle attachments. */ $queue = null; foreach (['estimate', 'bill', 'voucher'] as $document) { if ($attachments->has($document)) { /** * If document isn't generated yet, generate it first. */ if (!$order->{$document . '_url'}) { $queue = queue()->create($document . ':generate', ['orders' => $order->id])->after($queue); } $data['attach'][$document] = __('document.' . $document . '.title', ['order' => $order]); } } /** * Set subject and content, they will be parsed later ... */ $data['subject'] = $template['subject']; $data['content'] = $template['content']; /** * Put them to queue. */ queue()->create('mail:send', ['user' => $receiver, 'data' => $data])->after($queue); }); return $this->response()->respondWithSuccess(); }