Download the PHP package huangdijia/laravel-trigger without Composer

On this page you can find all versions of the php package huangdijia/laravel-trigger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-trigger

laravel-trigger

Latest Test Latest Stable Version Total Downloads GitHub license

Subscribe to MySQL events like jQuery, based on php-mysql-replication

中文说明

Quick Start

  1. Install the package: composer require "huangdijia/laravel-trigger:^4.0"
  2. Configure your MySQL server for replication (see MySQL Server Configuration)
  3. Publish the config: php artisan vendor:publish --provider="Huangdijia\Trigger\TriggerServiceProvider"
  4. Configure your .env file with database credentials
  5. Start listening: php artisan trigger:start

Table of Contents

MySQL Server Configuration

Replication Settings

In your MySQL server configuration file, you need to enable replication:

[mysqld]
server-id        = 1
log_bin          = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size  = 100M
binlog_row_image = full
binlog-format    = row #Very important if you want to receive write, update and delete row events

For more information: MySQL replication events explained

User Privileges

Grant the necessary privileges to your MySQL user:

GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user'@'host';

GRANT SELECT ON `dbName`.* TO 'user'@'host';

Installation

Laravel

Install via Composer:

composer require "huangdijia/laravel-trigger:^4.0"

Publish the configuration file:

php artisan vendor:publish --provider="Huangdijia\Trigger\TriggerServiceProvider"

Lumen

Install via Composer:

composer require "huangdijia/laravel-trigger:^4.0"

Edit bootstrap/app.php and add:

$app->register(Huangdijia\Trigger\TriggerServiceProvider::class);
...
$app->configure('trigger');

Publish configuration and routes:

php artisan trigger:install [--force]

Configure

Edit your .env file and add the following configuration:

TRIGGER_HOST=192.168.xxx.xxx
TRIGGER_PORT=3306
TRIGGER_USER=username
TRIGGER_PASSWORD=password
...

Connection Timeouts (Recommended)

If your MySQL server (or a proxy in front of it) disconnects idle clients (low wait_timeout / interactive_timeout), the trigger process may crash with errors like:

SQLSTATE[HY000] ... 4031 The client was disconnected by the server because of inactivity.

To improve stability, enable a keepalive ping and/or set session variables for the trigger's MySQL metadata connection:

# Ping MySQL periodically (seconds). Set to 0 to disable.
TRIGGER_KEEPALIVE=60

# Session variables applied on connect (comma-separated key=value pairs).
TRIGGER_SESSION_VARIABLES=wait_timeout=7200,interactive_timeout=7200,net_read_timeout=3600,net_write_timeout=3600

Usage

Start the trigger service to begin listening for MySQL events:

php artisan trigger:start [-R=xxx]

The service will monitor your MySQL binary log and trigger registered event handlers when database changes occur.

Event Subscribers

Create a custom event subscriber by extending the EventSubscriber class:

For more subscriber usage examples, see: EventSubscribers

Event Routes

Basic Usage

$trigger->on('database.table', 'write', function($event) { /* do something */ });

Multi-tables and Multi-events

$trigger->on('database.table1,database.table2', 'write,update', function($event) { /* do something */ });

Multi-events

$trigger->on('database.table1,database.table2', [
    'write'  => function($event) { /* do something */ },
    'update' => function($event) { /* do something */ },
]);

Action as Controller

$trigger->on('database.table', 'write', 'App\\Http\\Controllers\\ExampleController'); // calls default method 'handle'
$trigger->on('database.table', 'write', 'App\\Http\\Controllers\\ExampleController@write');

Action as Callable

class Foo
{
    public static function bar($event)
    {
        dump($event);
    }
}

$trigger->on('database.table', 'write', 'Foo@bar');
$trigger->on('database.table', 'write', ['Foo', 'bar']);

Action as Job

Define your job class:

namespace App\Jobs;

class ExampleJob extends Job
{
    private $event;

    public function __construct($event)
    {
        $this->event = $event;
    }

    public function handle()
    {
        dump($this->event);
    }
}

Register the job route:

$trigger->on('database.table', 'write', 'App\Jobs\ExampleJob'); // calls default method 'dispatch'
$trigger->on('database.table', 'write', 'App\Jobs\ExampleJob@dispatch_now');

Management Commands

List Events

View all registered event listeners:

php artisan trigger:list [-R=xxx]

Terminate Service

Stop the trigger service gracefully:

php artisan trigger:terminate [-R=xxx]

Thanks to

JetBrains


All versions of laravel-trigger with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0 || ^12.0 || ^13.0
illuminate/console Version ^11.0 || ^12.0 || ^13.0
krowinski/php-mysql-replication Version ^8.0 || ^9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package huangdijia/laravel-trigger contains the following files

Loading the files please wait ...