gandung / task-queue
Task queue library written in PHP
v1.0.2
2017-09-24 13:44 UTC
Requires
- php: >=5.6.0 || >=7.1.0
- gandung/dependency-injection: ^1.0
Requires (Dev)
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: ^2.7.0
This package is auto-updated.
Last update: 2024-12-21 05:28:52 UTC
README
Task queue library written in PHP.
Registering single task
Existing functions or callbacks:
<?php use TaskQueue\TaskQueue; use TaskQueue\Invoker\FunctionInvoker; $taskQueue = new TaskQueue; $taskQueue->add(new FunctionInvoker('file_get_contents'), '/etc/passwd'); $taskQueue->run();
Closures:
<?php 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();
Class method with class name:
<?php use TaskQueue\TaskQueue; use TaskQueue\Invoker\MethodInvoker; $taskQueue = new TaskQueue; $taskQueue->add(new MethodInvoker(['instance' => \SplPriorityQueue::class, 'method' => 'count'])); $taskQueue->run();
Class method with class instance:
<?php use TaskQueue\TaskQueue; use TaskQueue\Invoker\MethodInvoker; $queue = new \SplPriorityQueue; $taskQueue = new TaskQueue; $taskQueue->add(new MethodInvoker(['instance' => $queue, 'method' => 'count'])); $taskQueue->run();
Registering multiple tasks
Existing functions or callbacks:
<?php 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();
Closures:
<?php 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();
Unit testing
vendor/bin/phpunit