PHPackages                             assetplan/dispatcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. assetplan/dispatcher

ActiveLibrary[Queues &amp; Workers](/categories/queues)

assetplan/dispatcher
====================

Dispatch jobs securely from other applications

v0.4.0(6mo ago)026.4k↓50%[5 PRs](https://github.com/AssetPlan/dispatcher/pulls)MITPHPPHP ^8.1CI failing

Since Apr 21Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/AssetPlan/dispatcher)[ Packagist](https://packagist.org/packages/assetplan/dispatcher)[ Docs](https://github.com/assetplan/dispatcher)[ RSS](/packages/assetplan-dispatcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (4)Versions (18)Used By (0)

Assetplan Dispatcher
====================

[](#assetplan-dispatcher)

Assetplan Dispatcher is a lightweight PHP package that allows you to dispatch jobs between multiple applications using HTTP requests. This can be useful in distributed systems where jobs need to be executed on remote machines.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require assetplan/dispatcher
```

Usage
-----

[](#usage)

### Setting up the backend

[](#setting-up-the-backend)

Before you can start dispatching jobs, you need to set up a backend application that will receive the dispatched jobs. This can be any PHP application that can handle HTTP requests. You'll need to set the following environment variables to configure the backend:

```
# in the backend
DISPATCHER_BACKEND_SECRET=your-secret
DISPATCHER_IS_BACKEND=true
```

```
# in the machine that will dispatch the jobs
DISPATCHER_BACKEND_URL=http://localhost:8000
DISPATCHER_BACKEND_SECRET=your-secret
```

The `DISPATCHER_BACKEND_URL` variable should point to the URL of the backend application. The `DISPATCHER_BACKEND_SECRET` variable is a shared secret that is used to sign the dispatched jobs. Make sure to keep this secret secure.

### Generating a secret key

[](#generating-a-secret-key)

The `dispatcher:generate-secret` command allows you to generate a secret key that is used to sign the dispatched jobs. You can use this command to generate a new secret key or replace an existing one.

To generate a new secret key, run the following command:

```
php artisan dispatcher:generate-secret
```

By default, the command generates a 64-character secret key and saves it in the .env file of your application. If the .env file does not exist, the command will display an error message.

You can use the `--length` option to specify the length of the secret key. For example, to generate a 128-character secret key, run the following command:

```
php artisan dispatcher:generate-secret --length=128
```

You can use the --show option to display the generated secret key in the console. For example, to generate a new secret key and display it in the console, run the following command:

```
php artisan dispatcher:generate-secret --show
```

You can use the --no-replace option to generate a new secret key without replacing an existing one. For example, to generate a new secret key without replacing an existing one, run the following command:

```
php artisan dispatcher:generate-secret --no-replace
```

If the `.env` file already contains a `DISPATCHER_BACKEND_SECRET` variable, the command will replace its value with the newly generated secret key. If the `.env` file does not contain a `DISPATCHER_BACKEND_SECRET` variable, the command will add the variable and its value to the file.

**Note:** If you are running the command in a production environment, the command will display a warning message and exit without generating a new secret key. This is to prevent accidental changes to production settings.

### Configuration

[](#configuration)

The package comes with a configuration file that allows you to customize its behavior. You can publish the configuration file by running the following command:

```
php artisan vendor:publish --provider="Assetplan\Dispatcher\DispatcherServiceProvider" --tag="config"
```

Once you have published the configuration file, you can customize the following options:

- `url`: The URL of the backend server where the jobs will be dispatched.
- `secret`: The secret key that will be used to sign the jobs before dispatching them.
- `is_backend`: Whether the current server is the backend server or not.
- `aliases`: You can register aliases to make it easier to dispatch your jobs. These aliases only need to be registered in the backend server and are optional.

### Aliases

[](#aliases)

The `aliases` configuration option allows you to register custom aliases for job classes. This can be useful to avoid typing the fully qualified class name of a job every time you dispatch it.

Here's an example of how to register an alias in the dispatcher.php config file:

```
