PHP code example of mjphaynes / php-resque

1. Go to this page and download the library: Download mjphaynes/php-resque 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/ */

    

mjphaynes / php-resque example snippets




use Resque\Blueprint\Job as JobBlueprint;
use Resque\Job;

class MyJob extends JobBlueprint
{
    /**
     * Runs any  /**
     * Actual job logic.
     *
     * @param array $args Arguments passed to the job
     * @param Job   $job  Current job instance
     */
    public function perform(array $args, Job $job): void
    {
        // Do some work
    }

    /**
     * Runs after the job is performed.
     *
     * @param Job $job Current job instance
     */
    public function tearDown(Job $job): void
    {
    }
}


$job = Resque::push(MyJob::class, ['arg1' => true, 'arg2']);

$job = Resque::push(function ($job) {
    echo "This is a inline job {$job->getId()}!";
});

$job = Resque::push(SendEmail::class, [], 'email');

$job = Resque::later(60, MyJob::class);
$job = Resque::later(1398643990, MyJob::class);
$job = Resque::later(new \DateTime('+2 mins'), MyJob::class);
$job = Resque::later(new \DateTime('2014-07-08 11:14:15'), MyJob::class);

$job = Resque::push(MyJob::class);
$jobId = $job->getId();

$job = Job::load($jobId);
$status = $job->getStatus();

foreach(Worker::allWorkers() as $worker) {
    $worker->shutdown();
}