PHP code example of pollsockets / pollsockets-laravel

1. Go to this page and download the library: Download pollsockets/pollsockets-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pollsockets / pollsockets-laravel example snippets


use Pollsockets\Drivers\RedisChannel;

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

    // Redis connection name. null uses the default connection.
    'connection' => null,

    // Events older than this many seconds are pruned on the next publish. Must be at least 1.
    'retention' => 60,

    // Request header that carries the publishing client's id.
    'client_header' => 'X-Pollsockets-Client',

    'route' => [
        'prefix' => '_pollsockets',

        // e.g. ['web', 'auth'] if your event names are sensitive.
        'middleware' => [],
    ],
];

use Pollsockets\Pollsockets;

// A channel separates events from different sources, e.g. one channel per team.
// Channel names may contain letters, digits, "_", ".", ":" and "-".
Pollsockets::channel('team.1')->publish('coupons');

DB::transaction(function () {
    // ... write the coupons
    DB::afterCommit(fn () => Pollsockets::channel('team.1')->publish('coupons'));
});

public function index()
{
    $since = Pollsockets::now(); // before the queries

    return view('coupons.index', [
        'coupons' => Coupon::all(),
        'pollsocketsSince' => $since,
    ]);
}
bash
php artisan vendor:publish --tag="pollsockets-config"