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' 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); // return ['failed','completed']
// Waits until the job succeeds or fails. If you want to manage all processes, send the 'manageable' value as 'true'.
$status = await($job, true); // return ['pending','processing','failed','completed']
# You can 'use' statement.
$variable = "initial";
async(function () use (&$variable){
$variable = "changed";
});
echo $variable; # print "initial"