1. Go to this page and download the library: Download zotlo/phalcon-queue library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$jobArray = [
new MyJob(),
new MyJob(),
...
];
dispatchBatch($jobArray);
# Also, you can set queue with batch.
dispatchBatch($jobArray)
->queue('default');
async(function () {
...
});
# You can use the 'use' statement.
$uniqId = uniqid();
async(function () use ($uniqId) {
$taskId = $uniqId;
...
});
$job = async(function () {
...
});
// Your app codes
// Waits until the job succeeds or fails.
$status = await($job); // Status::COMPLETED or Status::FAILED
// If you want to manage all states yourself, pass 'manageable' as true;
// pending/processing states are then returned immediately instead of blocking.
$status = await($job, true); // Status::PENDING, PROCESSING, FAILED or COMPLETED
$variable = "initial";
async(function () use (&$variable) {
$variable = "changed";
});
echo $variable; # prints "initial"
use Phalcon\Queue\Channel;
$ch = Channel::make();
$token = uniqid();
async(function () use ($token, $ch) {
// heavy work...
sleep(rand(2, 10));
$ch->write(json_encode(['status' => true, 'msg' => 'message received!', 'id' => $token]));
});
// Blocks until a message arrives (or the timeout expires).
$channelData = $ch->read();
echo $channelData; # {"status":true,"msg":"message received!","id":"..."}
$ch = Channel::make(); # create a single channel
$channels = Channel::makes(5); # create multiple channels at once
$ch->write(string $message): bool; # write a message (max 128 KB)
$ch->read(int $timeout = 15): ?string; # read one message; null if none arrives within $timeout seconds
$ch->readAll(int $timeout = 15): array; # collect all messages arriving within $timeout seconds
$console = new Symfony\Component\Console\Application('Phalcon Queue Management', '1.0.0');
$console->addCommands([
(new \Phalcon\Queue\Commands\ListFailedJobCommand())->setDi($di),
(new \Phalcon\Queue\Commands\RetryFailedJobCommand())->setDi($di),
(new \Phalcon\Queue\Commands\RestartQueueCommand())->setDi($di),
(new \Phalcon\Queue\Commands\ForceStopQueueCommand())->setDi($di),
]);
$console->run();