Support the ongoing development of Laravel.io →
posted 9 years ago
Queues
Last updated 2 years ago.
0

I have the same doubt... Can someone help us? :-)

0

i have this setup:

in my composer.json: "illuminate/queue": "^5.1", "pda/pheanstalk": "^3.0", "illuminate/encryption": "^5.1"

to add queues:

    $queue = new Queue;

    $queue->addConnection([
        'driver' => 'beanstalkd',
        'host'   => 'localhost',
        'queue'  => 'default',
    ]);

    $queue->setAsGlobal();

    $queue->getContainer()->bind('encrypter', function () {
        return new Illuminate\Encryption\Encrypter('joongo5Ie2thie8k');
    });
    $queue->getContainer()->bind('request', function () {
        return new Illuminate\Http\Request();
    });

    $queue->push('SendEmail', ['foo' => 'demo']);

get the worker running:

    $queue = new Queue;

    $queue->addConnection([
        'driver' => 'beanstalkd',
        'host'   => 'localhost',
        'queue'  => 'default',
    ]);

    $queue->setAsGlobal();

    $queue->getContainer()->bind('encrypter', function () {
        return new Illuminate\Encryption\Encrypter('joongo5Ie2thie8k');
    });
    $queue->getContainer()->bind('request', function () {
        return new Illuminate\Http\Request();
    });
    
    $worker = new Worker($queue->getQueueManager(), null, null);


    while (true) {
        // Parameters:
        // 'default' - connection name
        // 'default' - queue name
        // delay
        // time before retries
        // max number of tries

        $worker->pop('default', 'default', 0, 3, 1);
    }
}

and important: add some class SendEmail that implements: public function fire($job, $data)

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.