PHP code example of gandung / task-queue

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

    

gandung / task-queue example snippets




use TaskQueue\TaskQueue;
use TaskQueue\Invoker\FunctionInvoker;

$taskQueue = new TaskQueue;

$taskQueue->add(new FunctionInvoker('file_get_contents'), '/etc/passwd');

$taskQueue->run();



use TaskQueue\TaskQueue;
use TaskQueue\Invoker\FunctionInvoker;

$taskQueue = new TaskQueue;

$closure = function() {
	echo "Hello with closures." . PHP_EOL;
};

$taskQueue->add(new FunctionInvoker($closure));

$taskQueue->run();



use TaskQueue\TaskQueue;
use TaskQueue\Invoker\MethodInvoker;

$taskQueue = new TaskQueue;

$taskQueue->add(new MethodInvoker(['instance' => \SplPriorityQueue::class, 'method' => 'count']));

$taskQueue->run();



use TaskQueue\TaskQueue;
use TaskQueue\Invoker\MethodInvoker;

$queue = new \SplPriorityQueue;
$taskQueue = new TaskQueue;

$taskQueue->add(new MethodInvoker(['instance' => $queue, 'method' => 'count']));

$taskQueue->run();



use TaskQueue\TaskQueue;
use TaskQueue\Invoker\FunctionInvoker;

$taskQueue = new TaskQueue;

$taskQueue
	->add(new FunctionInvoker('file_get_contents'), '/etc/passwd')
	->add(new FunctionInvoker('printf'), '%d' . PHP_EOL, 31337);

$taskQueue->run();



use TaskQueue\TaskQueue;
use TaskQueue\Invoker\FunctionInvoker;

$taskQueue = new TaskQueue;

$closures = [
	function() {
		echo "This will be a second run." . PHP_EOL;
	},
	function() {
		echo "This will be a first run." . PHP_EOL;
	}
];

$taskQueue
	->add(new FunctionInvoker($closures[0]))
	->add(new FunctionInvoker($closures[1]));

$taskQueue->run();