PHP code example of pmg / queue-pheanstalk

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

    

pmg / queue-pheanstalk example snippets


use Pheanstalk\Pheanstalk;
use PMG\Queue\DefaultConsumer;
use PMG\Queue\Driver\PheanstalkDriver;
use PMG\Queue\Serializer\NativeSerializer;
use PMG\Queue\Serializer\SigningSerializer;

// ...

$serilizer = new NativeSerializer('this is the secret key');

$driver = new PheanstalkDriver(new \Pheanstalk\Pheanstalk('localhost'), $serializer, [
    // how long easy message has to execute in seconds
    'ttr'               => 100,

    // the "priority" of the message. High priority messages are
    // consumed first.
    'priority'          => 1024,

    // The delay between inserting the message and when it
    // becomes available for consumption
    'delay'             => 0,

    // The ttr for retries jobs
    'retry-ttr'         => 100,

    // the priority for retried jobs
    'retry-priority'    => 1024,

    // When jobs fail, they are "burieds" in beanstalkd with this priority
    'fail-priority'     => 1024,

    // A call to `dequeue` blocks for this number of seconds. A zero or
    // falsy value will block until a job becomes available
    'reserve-timeout'   => 10,
]);

// $handler instanceof PMG\Queue\MessageHandler
$consumer = new DefaultConsumer($driver, $handler);

use Pheanstalk\Pheanstalk;
use PMG\Queue\DefaultConsumer;
use PMG\Queue\Driver\PheanstalkDriver;
use PMG\Queue\Driver\Pheanstalk\DeleteFailureStrategy;
use PMG\Queue\Serializer\NativeSerializer;

// ...

$serilizer = new NativeSerializer('this is the secret key');
$failureStrategy = new DeleteFailureStrategy();

$driver = new PheanstalkDriver(new \Pheanstalk\Pheanstalk('localhost'), $serializer, [
    // as above
], $failureStrategy);

// $handler instanceof PMG\Queue\MessageHandler
$consumer = new DefaultConsumer($driver, $handler);