Git Product home page Git Product logo

php-sse-react's Introduction

clue/sse-react

CI status installs on Packagist

Streaming, async HTML5 Server-Sent Events server (aka. SSE or EventSource), built on top of React PHP.

Note: This project is in early alpha stage! Feel free to report any issues you encounter.

Quickstart example

See the examples.

Install

The recommended way to install this library is through Composer. New to Composer?

Once released, this project will follow SemVer. At the moment, this will install the latest development version:

{
    "require": {
        "clue/sse-react": "dev-master"
    }
}

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through PHP 7.3. It's highly recommended to use the latest supported PHP version for this project.

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

composer install

To run the test suite, go to the project root and run:

php vendor/bin/phpunit

License

MIT, see LICENSE file.

php-sse-react's People

Contributors

clue avatar legionth avatar mahmutbayri avatar paulrotmann avatar saschanowak avatar simonfrings avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-sse-react's Issues

Memory leak in BufferedChannel writeMessage()

Hi Christian,

Found a "memory leak" in my local server using this component and isolated it to this class+method. The memory usage keeps growing indefinitely as more messages are passed to the WriteMessage() method as it never trims its internal arrays (both the bufferedData and bufferedType arrays can grow indefinitely large.)

Upgrade to new ReactPHP components

This component uses outdated Http and deprecated SocketClient which has been replaced by Socket. Updating this will involve a BC break to the API.

Opening this ticket for the reference and will address this soon-ish.

EventSource's response has a MIME type

I'm testing out react with addition of clue/php-sse-reactt, but can't make it work properly.
I'm using server like in the example:


require __DIR__ . '/../vendor/autoload.php';

use Clue\React\Sse\BufferedChannel;
use React\Http\Request;
use React\Http\Response;


$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);

$channel = new BufferedChannel();

$http = new React\Http\Server($socket);

$http->on('request', function (Request $request, Response $response) use ($channel) {
    echo 'connected' . PHP_EOL;

    $headers = $request->getHeaders();
    $id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;

    $response->writeHead(200, array('Content-Type' => 'text/event-stream', 'Cache-Control' => 'no-cache'));
    $channel->connect($response, $id);

    $response->on('close', function () use ($response, $channel) {
        echo 'disconnected' . PHP_EOL;
        $channel->disconnect($response);
    });
});

$loop->addPeriodicTimer(2.0, function() use ($channel) {
    $channel->writeMessage('ticking ' . mt_rand(1, 5) . '...');
});

$socket->listen(1337);

echo 'Server now listening on localhost:' . $socket->getPort() . PHP_EOL;
$loop->run();

Than I run it with bash: $ php server.php

When I'm doing script:
var eventSource = new EventSource('server.php');

it gives an error:
EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.
What might be the problem?

Also I used
$ echo -e "GET / HTTP/1.0\r\n\r\n" | nc localhost 1337
and it returned

HTTP/1.1 200 OK
X-Powered-By: React/alpha
Content-Type: text/event-stream
Cache-Control: no-cache
Transfer-Encoding: chunked

BufferedChannel changed?

I was using Clue\React\Sse\BufferedChannel and it was working fine (as in example 11-chat.php.
Now apparently it was substituted by clue/sse-react, but I get an error on composer:
composer require clue/sse-react
[InvalidArgumentException]
Could not find a version of package clue/sse-react matching your minimum-stability (stable). Require it with an explicit version constraint allo
wing its desired stability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.