Trigger Laravel Events with mulitple workers, threads, delays & throttles.
This package uses react-thread-pool that is a dev release and this package itself is very experimental.
- Laravel 5.2.*
- PHP >= 5.4, only tested on 7.
- pcntl
- Linux/Unix
Install with composer
composer require askedio/laravel-event-worker
Register the provider
in config/app.php
.
Askedio\EventWorker\Providers\LaravelEventWorkerServiceProvider::class,
Publish the config.
php artisan vendor:publish
The default config uses the App\Events\FetchTwitterEvent
event, create it or edit configs/event-workers.php
to use your events.
Create the event.
php artisan make:event FetchTwitter
Edit app/Events/FetchTwitterEvent.php
and make it do something, like..
public function __construct($iteration)
{
echo "Hello world.".PHP_EOL;
}
Certainly you'll put stuff in the listener and make a proper event, but you get the idea.
Run it.
php artisan events:serve
In configs/event-workers.php
you define the events you want to run.
return [
'twitter' => [ // name
'delay' => 1, // delay between creating threads
'throttle' => '1:1', // throttle for creating threads
'workers' => 1, // number of workers to create
'threads' => [
'min' => 1, // minium threads per worker
'max' => 3, // maximum threads per worker
'timeout' => 30, // thread time out
],
'class' => \App\Events\FetchTwitterEvent::class, // your event class
],
];
Ya right. I aint got time for that.
That'd be swell. Send a PR.