mrananyan/parrot

An long polling stack for PHP-based real-time applications

1.0.0 2021-03-28 18:05 UTC

This package is auto-updated.

Last update: 2024-04-29 04:40:43 UTC


README

An easy to use Facebook like long polling stack for PHP-based real-time applications

logo.png

Demo

Demo app Demo app source

Requirements

  • Redis
  • PHP-FPM
  • Nginx

Installation

composer require mrananyan/parrot:1.0.0

How setup

  1. Configuration

If you want to connect via TCP (Recommended for remote server)

$parameters = [
                  'scheme' => 'tcp',
                  'host'   => '127.0.0.1',
                  'port'   => 6379,
              ];

If you want to connect via UNIX socket (Recommended if Redis on same server)

$parameters = [
                  'scheme' => 'unix',
                  'path'   => '/var/run/redis/redis.sock',
              ];
  1. Worker. You can subscribe to many channels at once if you need. ('chanel1','chanel2' ...)
use Parrot\Server\Worker;

$parrotWorker = new Worker($parameters);
$messages = $parrotWorker->subscribe('myChanel');
echo json_encode($messages);
  1. Publisher. Send message to users who subscribed to myChanel chanel
use Parrot\Client\Publisher;

$publisher = new Publisher($parameters);
$publisher->set('myChanel', 'Your message string here');