2017 © Pedro Peláez
 

library laravel-event-worker

A Laravel Event Worker

image

askedio/laravel-event-worker

A Laravel Event Worker

  • Wednesday, June 1, 2016
  • by gcphost
  • Repository
  • 2 Watchers
  • 3 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel Event Worker

Trigger Laravel Events with mulitple workers, threads, delays & throttles., (*1)

minimum-stability: dev

This package uses react-thread-pool that is a dev release and this package itself is very experimental., (*2)

Requirements

  • Laravel 5.2.*
  • PHP >= 5.4, only tested on 7.
  • pcntl
  • Linux/Unix

Installation

Install with composer, (*3)

composer require askedio/laravel-event-worker

Register the provider in config/app.php., (*4)

Askedio\EventWorker\Providers\LaravelEventWorkerServiceProvider::class,

Publish the config., (*5)

php artisan vendor:publish

Usage

The default config uses the App\Events\FetchTwitterEvent event, create it or edit configs/event-workers.php to use your events., (*6)

Create the event., (*7)

php artisan make:event FetchTwitter

Edit app/Events/FetchTwitterEvent.php and make it do something, like.., (*8)

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., (*9)

Run it., (*10)

php artisan events:serve

Configuration

In configs/event-workers.php you define the events you want to run., (*11)

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
  ],
];

Testing

Ya right. I aint got time for that., (*12)

Contributing

That'd be swell. Send a PR., (*13)

The Versions