We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Question about benstalkd queue

I want to add two phase authentication in my website login process, thus I want to send an SMS to my user with random access code, benstalkd can help to asynchronous send the message, and improvement user experience. And you can easy to see, this is a time sensitive process, so it cannot be added into crontab, I want my send process can be notified when a new job put into the queue.

Any idea? Thanks in advanced.

index.php

$di->set('queue', function() use ($config) {
    $queue = new Phalcon\Queue\Beanstalk(array(
        'host' => $config->queue->host,
        'port' => $config->queue->port
    ));

    return $queue;
});


29.1k

register a callback function or observer? how?



29.1k

How about:

!/usr/local/bin/php -q

<?php // Stop the script giving time out errors.. set_time_limit(0);

// Main loop while(true) { $queue = new Phalcon\Queue\Beanstalk(array( 'host' => '127.0.0.1', 'port' => 11300 )); while (($job = $this->queue->peekReady()) !== false) { $job = $this->queue->reserve(); $message = $job->getBody();

    //...

    $job->delete();
}
sleep(1);

}