PHP code example of sunvalley-technologies / php-task-manager
1. Go to this page and download the library: Download sunvalley-technologies/php-task-manager 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/ */
sunvalley-technologies / php-task-manager example snippets
$loop = \React\EventLoop\Factory::create();
$queue = new \SunValley\TaskManager\TaskQueue\InMemoryTaskQueue($loop);
$configuration = new \SunValley\TaskManager\Configuration();
$configuration->setMaxJobsPerProcess(2);
$configuration->setMaxProcesses(3);
$configuration->setTtl(1);
$taskManager = new \SunValley\TaskManager\TaskManager($loop, $queue, $configuration);
$task = new ExampleTask(uniqid(), ['data'=>'some data']);
$promise = $taskManager->submitTask($task); // promise resolves to a result object
$promise->then(function(\SunValley\TaskManager\ProgressReporter $reporter) use ($loop) {
if ($reporter->isFailed()) {
echo sprintf("Task is Failed! Error is %s", $reporter->getError());
} else {
echo sprintf("Task Completed, Result is '%s'!", $reporter->getResult());
}
$loop->stop();
});
// or
// $queue->enqueue($task); which works from any context
$loop->run();