PHP code example of pnixx / delayed_job

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

    

pnixx / delayed_job example snippets


class TestJob extends PNixx\DelayedJob\Job {

	public function perform($args = []): void {
		//Work process
	}
}

class TestJob extends PNixx\DelayedJob\Job {

	/**
	 * Queue for publishing Job
	 */
	public static string $queue = 'mailer';
	
	/**
	 * Attempt count used for only delayed tasks
	 * default: 0 - always repeat until it reach success
	 */
	public static $attempt = 0;

	public function setup() {
		//Setup this job
	}

	public function perform($args = []): void {
		//Work process
	}

	public function completed() {
		//Complete job callback
	}
}

//Run job in this thread without arguments
TestJob::now();

//Run job in this thread with arguments
TestJob::now(['name' => 'Jane']);

//Run job in a background
TestJob::later();

//Run job in a background with arguments
TestJob::later(['name' => 'Jane']);

//Add job in a scheduler.
TestJob::later(['name' => 'Jane'], strtotime('+1 day'));