This is Laravel package for phpsocket.io which is a server side alternative implementation of socket.io in PHP based on Workerman.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Require this package, with Composer, in the root directory of your project.
$ composer require sanchescom/laravel-phpsocket.io
Create SocketServiceProvider.php
in app/Providers
<?php
namespace App\Providers;
use Sanchescom\LaravelSocketIO\SocketServiceProvider as ServiceProvider;
use App\Sockets\ExampleSocket;
/**
* Class SocketServiceProvider.
*/
class SocketServiceProvider extends ServiceProvider
{
/**
* The socket handlers for the application.
*
* @var array
*/
protected $sockets = [
ExampleSocket::class,
];
}
After updating composer, add the ServiceProvider to the providers array in config/app.php
'providers' => [
...
App\Providers\SocketServiceProvider::class,
],
After updating composer add the following lines to register provider in bootstrap/app.php
$app->register(App\Providers\SocketServiceProvider::class);
Create folder app\Sockets
and put there ExampleSocket.php
<?php
namespace App\Sockets;
use PHPSocketIO\SocketIO;
use Sanchescom\LaravelSocketIO\Sockets\AbstractSocket;
use Workerman\Lib\Timer;
class ExampleSocket extends AbstractSocket
{
/**
* @var int
*/
const TIME_INTERVAL = 4;
/**
* @var int
*/
protected $port = 2020;
/**
* @var array
*/
protected $options = [];
/**
* @param SocketIO $socketIO
*/
public function call(SocketIO $socketIO): void
{
$socketIO->on('workerStart', function () use ($socketIO) {
Timer::add(self::TIME_INTERVAL, function () use ($socketIO) {
$socketIO->to('room')->emit('score', [
'items' => [
[
'id' => 1,
'message' => 'Hello world'
],
]
]);
});
});
$socketIO->on('connection', function ($socket) {
$socket->join('room');
});
}
}
$ ./vendor/bin/socket start
$ ./vendor/bin/socket stop
$ ./vendor/bin/socket status
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Efimov Aleksandr - Initial work - Sanchescom
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details