A Laravel server side alternative implementation of in PHP based on Workerman.

dev-master 2018-08-17 07:44 UTC

This package is not auto-updated.

Last update: 2022-11-20 03:23:21 UTC


A Larvel server side alternative implementation of in PHP based on Workerman.


  • php: >=5.3
  • Laravel: >= 5.0


You can install this package via composer using this command:

composer require armandgarot/laravel-workerman

You can publish the config-file with:

php artisan vendor:publish --provider="ArmandGarot\LaravelWorkerman\LaravelWorkermanServiceProvider" --tag="config"


php artisan workerman:server start
php artisan workerman:server stop
php artisan workerman:server status


Simple chat

// app/Events/SendChatMessage.php

namespace App\Events;

use Illuminate\Console\Command;

class SendChatMessage extends Command
     * Create a new event instance.
     * @param PHPSocketIO\SocketIO $server
     * @return void
    public function __construct($server)
		$server->on('connection', function($socket) use($server) {
			$socket->on('chat message', function($message) use($server) {
				$server->emit('chat message', $message);
// resources/views/chat.blade.php

<!doctype html>
<html lang="{{ app()->getLocale() }}">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>{{ config('') }}</title>

        <!-- Styles -->
		<link href="" rel="stylesheet">
		<div class="container">
			<div class="row justify-content-center">
				<div class="col-md-8">
					<div class="card mt-5">
						<div class="card-header">{{ config('') }}</div>

						<div class="card-body">
							<ul id="messages" class="list-group"></ul>
							<form class="mt-5">
								<div class="input-group mb-3">
									<input type="text" class="form-control" id="message" autocomplete="off" placeholder="Message">
									<div class="input-group-append">
										<button class="btn btn-primary" type="submit">Send</button>
		<script src=""></script>
		<script src=""></script>
				var socket = io("http://localhost:{{ config('laravel-workerman.server.port') }}");
					socket.emit('chat message', $('#message').val());
					return false;
				socket.on('chat message', function(message){
					$('#messages').append($('<li class="list-group-item">').text(message));
// config/laravel-workerman.php

return [

     * Listen port for SocketIO client.
    'server' => [
		'port' => 3000,
	 * Events dispatched when SocketIO server is running.
	'events' => [
// routes/web.php

Route::get('/chat', function () {
    return view('chat');
php artisan workerman:server start

Go to http://your-app/chat