pollsockets/pollsockets-laravel

Serverside implementation of pollsockets taylored for Laravel

1.0.0 2023-03-31 20:09 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Why pollsockets?

Pollsockets is a simple, yet powerful, server-client communication library. It is designed to be used in situations where you need to send data from the server to the client. It is a great alternative to websockets, as it is much simpler to implement and use.

How does it work?

Pollsockets uses a simple polling mechanism to send events from the server to the client. Instead of polling an endpoint that returns data, pollsockets polls an endpoint that returns a list of events that have occurred, thus saving bandwidth and response time. The client then processes the events and updates the UI accordingly.

Ecosystem

Server side

Client side

Requirements

  • PHP 8.1 or higher
  • Laravel 9.0 or higher
  • Redis 6.0 or higher

Installation

You can install the package via composer:

composer require pollsockets/pollsockets-laravel

You can publish the config file with:

php artisan vendor:publish --tag="pollsockets-config"

This is the contents of the published config file:

use Pollsockets\Drivers\RedisChannel;

return [
    'driver' => RedisChannel::class,
];

Usage

use Pollsockets\Pollsockets;

// Channel name can be any string. Can be used to separate events from different sources.
$channelName = 'channel';
// Event name can be any string. Can be used to separate events of the same type.
$event = 'reload';

// Publish an event to the channel from anywhere in your code. Perfect for informing client about changes in the database.
Pollsockets::channel($channelName)->publish($event);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.