PHPackages                             smileymrking/laravel-gateway-worker - 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. [API Development](/categories/api)
4. /
5. smileymrking/laravel-gateway-worker

ActiveLibrary[API Development](/categories/api)

smileymrking/laravel-gateway-worker
===================================

GatewayWorker SDK for Laravel

1.5.0(2y ago)161.8k2MITPHP

Since Jun 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/smileymrking/laravel-gateway-worker)[ Packagist](https://packagist.org/packages/smileymrking/laravel-gateway-worker)[ RSS](/packages/smileymrking-laravel-gateway-worker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (9)Used By (0)

> [English](./README.md)｜[中文](./README_CN.md)

Laravel GatewayWorker
=====================

[](#laravel-gatewayworker)

In order to use [GatewayWorker](https://github.com/walkor/GatewayWorker) more elegantly in Laravel, I developed this extension based on GatewayWorker to make it ready to use.

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

[](#installation)

```
composer require smileymrking/laravel-gateway-worker
```

Configuration
-------------

[](#configuration)

### Laravel

[](#laravel)

1. Register the ServiceProvider and Facade in `config/app.php` (For Laravel 5.5 and above, no manual registration is required)

```
'providers' => [
    // ...
    SmileyMrKing\GatewayWorker\GatewayWorkerServiceProvider::class,
];
```

2. Publish the configuration file:

```
php artisan vendor:publish --provider="SmileyMrKing\GatewayWorker\GatewayWorkerServiceProvider"
```

3. Modify the corresponding configurations in `config/gateway-worker.php` located in the application root directory.

### Lumen

[](#lumen)

> Lumen has not been used or tested, the following instructions are based on other extension package development.

1. In `bootstrap/app.php` around line 82:

```
$app->register(SmileyMrKing\GatewayWorker\GatewayWorkerServiceProvider::class);
```

2. Publish the `config/gateway-worker.php` configuration file by copying it from `vendor/smileymrking/laravel-gateway-worker/config/gateway-worker.php` to the `project_root/config` directory.

The configuration file already has a default websocket service named 'push', you can adjust the relevant configurations accordingly, or directly proceed to the next step to start the service.

```
return [

    /*
    |--------------------------------------------------------------------------
    | Gateway Worker Service
    |--------------------------------------------------------------------------
    */

    'default_service' => 'push', # Set Gateway::$registerAddress to push.register_address by default

    'push' => [
        'lan_ip' => env('WS_LAN_IP', '127.0.0.1'), # Internal IP, fill in the real internal IP when deploying in a multi-server distributed environment.

        'register' => env('WS_REGISTER', 'text://0.0.0.0:20000'),
        'register_address' => env('WS_REGISTER_ADDRESS', '127.0.0.1:20000'), # Registration service address

        'worker_name' => 'PushBusinessWorker', # Set the name of the BusinessWorker process
        'worker_count' => 1, # Set the number of BusinessWorker processes
        # Set which class to handle business logic. The class must implement the static method 'onMessage'. 'onConnect' and 'onClose' static methods are optional.
        'event_handler' => \SmileyMrKing\GatewayWorker\Push\PushEvent::class,

        'gateway' => env('WS_GATEWAY', 'websocket://0.0.0.0:20010'),# Address allowed for connection
        'gateway_name' => 'PushGateway', # Set the name of the Gateway process for easy statistics in the 'status' command
        'gateway_count' => 1, # Number of Gateway processes
        'start_port' => env('WS_START_PORT', '20100'),  # Starting port for listening on the local machine
        'ping_interval' => 55,  # Heartbeat interval, only for server-side heartbeat
        'ping_not_response_limit' => 1,   # 0: server actively sends heartbeat, 1: client actively sends heartbeat
        'ping_data' => '{"type":"ping"}', # Data for the server to actively send heartbeat, only for server-side heartbeat. When the client times out without sending heartbeat, the server will actively send a heartbeat detection.

        'gateway_start' => true,
        'business_worker_start' => true,
        'register_start' => true,

        'gateway_transport' => 'tcp', // When set to 'ssl', SSL will be enabled, websocket+SSL is 'wss'
        /*'gateway_context' => [
            // For more SSL options, please refer to the manual: http://php.net/manual/en/context.ssl.php
            'ssl' => array(
                // Please use absolute paths
                'local_cert' => '/your/path/of/server.pem', // It can also be a crt file
                'local_pk' => '/your/path/of/server.key',
                'verify_peer' => false,
                'allow_self_signed' => true, // Enable this option if it's a self-signed certificate
            )
        ],*/
    ],

    'pid_file' => null, // Custom PID file absolute path, by default in 'vendor/smileymrking/laravel-gateway-worker/src/GatewayWorker/worker' directory
    'log_file' => null, // Custom log file absolute path, same as above by default

];
```

### Starting the service

[](#starting-the-service)

Use the following command to start the service: `php artisan gateway-worker {serviceName} {action} {--d}`

ParameterDescriptionserviceNameService name, which is the key name in the configuration file.actionAction command, available commands are `status`, `start`, `stop`, `restart`, `reload`, `connections`.--dUse DAEMON mode.```
> php artisan gateway-worker push start

Workerman[gateway-worker push] start in DEBUG mode
----------------------------------------------- WORKERMAN -----------------------------------------------
Workerman version:4.0.6          PHP version:7.2.5-1+ubuntu18.04.1+deb.sury.org+1
------------------------------------------------ WORKERS ------------------------------------------------
proto   user            worker                listen                       processes    status
tcp     vagrant         PushGateway           websocket://0.0.0.0:20010    1             [OK]
tcp     vagrant         PushBusinessWorker    none                         1             [OK]
tcp     vagrant         Register              text://0.0.0.0:20000         1             [OK]
---------------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
```

> 'push' is the default service name that was created, you can synchronize the configuration file and modify the relevant configurations as needed.

Creating Multiple Services
--------------------------

[](#creating-multiple-services)

> You can start multiple services simultaneously.

#### Adding a new service

[](#adding-a-new-service)

Directly copy a duplicate of the 'push' configuration file and make the necessary modifications, paying attention to updating the 'worker\_name', 'gateway\_name', and related port configurations to avoid duplication. The key used in the configuration will be the service name.

```
return [
// ...
'demo' => [
        'lan_ip' => env('WS_LAN_IP_DEMO', '127.0.0.1'), # Internal IP, fill in the real internal IP when deploying in a multi-server distributed environment.

        'register' => env('WS_REGISTER_DEMO', 'text://0.0.0.0:20000'),
        'register_address' => env('WS_REGISTER_ADDRESS_DEMO', '127.0.0.1:20000'), # Registration service address

        'worker_name' => 'DemoBusinessWorker', # Set the name of the BusinessWorker process
        'worker_count' => 1, # Set the number of BusinessWorker processes
        # Set which class to handle business logic. The class must implement the static method 'onMessage'. 'onConnect' and 'onClose' static methods are optional.
        'event_handler' => \App\GatewayWorker\Demo\DemoEvent::class,

        'gateway' => env('WS_GATEWAY_DEMO', 'websocket://0.0.0.0:20010'),# Address allowed for connection
        'gateway_name' => 'DemoGateway', # Set the name of the Gateway process for easy statistics in the 'status' command
        'gateway_count' => 1, # Number of Gateway processes
        'start_port' => env('WS_START_PORT_DEMO', '20100'),  # Starting port for listening on the local machine
        'ping_interval' => 55,  # Heartbeat interval, only for server-side heartbeat
        'ping_not_response_limit' => 1,   # 0: server actively sends heartbeat, 1: client actively sends heartbeat
        'ping_data' => '{"type":"ping"}', # Data for the server to actively send heartbeat, only for server-side heartbeat. When the client times out without sending heartbeat, the server will actively send a heartbeat detection.

        'gateway_start' => true,
        'business_worker_start' => true,
        'register_start' => true,

        'gateway_transport' => 'tcp', // When set to 'ssl', SSL will be enabled, websocket+SSL is 'wss'
        /*'gateway_context' => [
            // For more SSL options, please refer to the manual: http://php.net/manual/en/context.ssl.php
            'ssl' => array(
                // Please use absolute paths
                'local_cert' => '/your/path/of/server.pem', // It can also be a crt file
                'local_pk' => '/your/path/of/server.key',
                'verify_peer' => false,
                'allow_self_signed' => true, // Enable this option if it's a self-signed certificate
            )
        ],*/
        'pid_file' => storage_path('logs/gateway-worker-demo.pid'),
        'log_file' => storage_path('logs/gateway-worker-demo.log'),
    ],

];
```

After completing the configuration modifications, use the `php artisan gateway-worker demo start` command to start the service, where 'demo' is the key name you configured.

#### Custom Event Handler

[](#custom-event-handler)

When 'event\_handler' is not configured, it will use the `SmileyMrKing\GatewayWorker\GatewayWorker\GatewayWorkerEvents` class, which implements the static methods 'onMessage', 'onConnect', and 'onClose'. You can customize the 'event\_handler' class by inheriting from `SmileyMrKing\GatewayWorker\GatewayWorker\GatewayWorkerEvents` and overriding the relevant static methods.

```
namespace App\GatewayWorker\Demo;

use SmileyMrKing\GatewayWorker\GatewayWorker\GatewayWorkerEvents;

class DemoEvent extends GatewayWorkerEvents
{
    public static function onMessage($client_id, $message)
    {
        // Do something
    }
}
```

The 'default\_service' configuration specifies which service's registration address Gateway::$registerAddress will connect to by default.

Message Pushing
---------------

[](#message-pushing)

You can directly use the `\GatewayWorker\Lib\Gateway` class in GatewayWorker. For specific usage, please refer to the [GatewayWorker manual](http://doc2.workerman.net/).

Viewing Logs
------------

[](#viewing-logs)

The logs and PID files are located in the `vendor/smileymrking/laravel-gateway-worker/src/GatewayWorker/worker` directory. You can customize the log and PID paths using the `pid_file` and `log_file` settings in the configuration.

References
----------

[](#references)

- [GatewayWorker 2.x 3.x Manual](http://doc2.workerman.net/)
- [Using Laravel to Carry Out Socket Communication in Workerman](https://learnku.com/articles/13151/using-laravel-to-carry-out-socket-communication-in-workerman)

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~162 days

Recently: every ~201 days

Total

8

Last Release

1022d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39133674?v=4)[smileymrking](/maintainers/smileymrking)[@smileymrking](https://github.com/smileymrking)

---

Top Contributors

[![smileymrking](https://avatars.githubusercontent.com/u/39133674?v=4)](https://github.com/smileymrking "smileymrking (40 commits)")

---

Tags

laravelsdkworkermanGatewayWorker

### Embed Badge

![Health badge](/badges/smileymrking-laravel-gateway-worker/health.svg)

```
[![Health](https://phpackages.com/badges/smileymrking-laravel-gateway-worker/health.svg)](https://phpackages.com/packages/smileymrking-laravel-gateway-worker)
```

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[saloonphp/laravel-plugin

The official Laravel plugin for Saloon

765.7M125](/packages/saloonphp-laravel-plugin)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

10710.0k](/packages/neuron-core-neuron-laravel)[jetimob/asaas-sdk-php-laravel

Laravel SDK for Asaa's API

194.7k](/packages/jetimob-asaas-sdk-php-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
