Download the PHP package pollsockets/pollsockets-laravel without Composer

On this page you can find all versions of the php package pollsockets/pollsockets-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pollsockets-laravel

Serverside implementation of pollsockets tailored for Laravel

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

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

Usage

Publishing events

An event name is any non-empty string without |. Each event is stored in a Redis sorted set pollsockets.{channel}, scored with the publish time in Unix milliseconds. Publishing the same event from the same origin again only moves its time forward, and the client fires each event name once per poll, not once per publish.

Events older than retention seconds are removed on the next publish to the channel.

Publish after the database transaction commits, for example inside DB::afterCommit(...) or after the transaction block. Otherwise a client can receive the event and reload before the new data is visible.

Polling

The client polls GET /_pollsockets/{channel}/poll?since=<ms> and gets:

The client keeps track of the cursor, skips its own events and detects when it was away for longer than the retention window. pollsockets-js 2.x does all of this for you.

Delivery and limitations

An event's score is the time read just before its ZADD, so events are not always stored in score order. A poll can return a newer event while an older-stamped event is not stored yet, and the cursor then moves past it. To cover this, the JS client re-reads the last 2 seconds on every poll and skips the events it already handled. A publish whose ZADD lands up to about 2 seconds after its timestamp is still delivered. A longer delay, for example a slow Redis connection, can cause the event to be missed.

Initial cursor

To make the client receive every change made after the page loaded its data, pass Pollsockets::now() to it as since. Capture the time before you load the data that the page shows, for example on the first line of the controller. A change published between the data query and a later timestamp would otherwise be missed.

With Inertia, put the timestamp in a prop that is resolved before the other props.

The client re-reads the 2 seconds before since, so right after start it can fire one extra notification for a change that the page already shows.

Without it, the client uses the time of its first poll response as the starting point.

Skipping the publishing tab (origin)

The browser tab that caused a change usually does not need to be notified about it. Send the client id of pollsockets-js in the X-Pollsockets-Client header (configurable with client_header) on your app's own write requests, for example with an HTTP interceptor. The id is stored as the event's origin, and that client skips the event.

The origin must match ^[A-Za-z0-9_-]{1,64}$. Any other value, and publishes without an HTTP request (queued jobs, console commands), store an empty origin, so every client receives the event.

Securing the poll route

Anyone who can reach the poll route can see the event names of a channel. The events carry no payload, but if the names or channel names are sensitive, protect the route with route.middleware, for example ['web', 'auth']. Note that polling through web starts and writes the session on every poll (about once per second per tab), and keeps the session alive while the tab is open.

Keeping the client in sync with the config

Upgrading from v1

Testing

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.


All versions of pollsockets-laravel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2|^8.3|^8.4
spatie/laravel-package-tools Version ^1.92.4
illuminate/contracts Version ^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pollsockets/pollsockets-laravel contains the following files

Loading the files please wait ...