1. Go to this page and download the library: Download switon/executor 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/ */
switon / executor example snippets
use Switon\Core\Attribute\Autowired;
use Switon\Core\RunnerInterface;
use Switon\Executor\ExecutorInterface;
use Switon\Executor\FutureInterface;
final class ReportRunner implements RunnerInterface
{
public function run(mixed $payload): array
{
return ['id' => $payload['id']];
}
}
final class ReportService
{
#[Autowired] protected ExecutorInterface $executor;
public function export(): array
{
$futures = $this->executor->invokeAll([
['report:daily', ['id' => 1]],
['report:weekly', ['id' => 2]],
]);
return array_map(static fn (FutureInterface $future) => $future->result(), $futures);
}
public function fallback(): mixed
{
return $this->executor->invokeAny([
['report:primary', ['id' => 1]],
['report:backup', ['id' => 1]],
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.