PHP code example of igorsantos07 / phalcon-queue-db

1. Go to this page and download the library: Download igorsantos07/phalcon-queue-db 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/ */

    

igorsantos07 / phalcon-queue-db example snippets


> use \Phalcon\Queue\Db as DbQueue;
> use \Phalcon\Queue\Db\Job as Job;
> 

class ImportantController {

    function veryImportantAction()
    {
        // Do some stuff and ends up with an emails array.
        
        // Instead of sending all those emails from the user request,
        // we are going to hand this job to a worker.
        $queue = new DbQueue();
        $queue->choose('email_notification'); //sets the tube we'll be using
        $queue->put($emailList);

        //tell the user to be happy because stuff went ok
    }
    
}

//adds a job on top of the queue
$queue->put($bossEmails, [DbQueue::OPT_PRIORITY => Job::PRIORITY_HIGHEST]);
//adds a job to be ran only later (in seconds)
$queue->put($taskReminder, [DbQueue::OPT_DELAY => 60 * 10]);

$queue->watch('email_notification');
while ($job = $queue->reserve()) {
    $payload = $job->getBody();
    //do stuff with the payload
    if ($worked) {
        $job->delete();
    } else {
        $job->bury();
    }
}