Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ from any Server-Sent Events (SSE) server endpoint:

```php
$loop = Factory::create();
$es = new EventSource('https://example.com/stream.php', $loop);
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);

$es->on('message', function (MessageEvent $message) {
$es->on('message', function (Clue\React\EventSource\MessageEvent $message) {
//$data = json_decode($message->data);
var_dump($message);
});
Expand All @@ -48,19 +48,19 @@ registers everything with the main [`EventLoop`](https://github.com/reactphp/eve
in order to handle async HTTP requests.

```php
$loop = \React\EventLoop\Factory::create();
$loop = React\EventLoop\Factory::create();

$es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
```

If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
proxy servers etc.), you can explicitly pass a custom instance of the
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance
to the [`Browser`](https://github.com/reactphp/http#browser) instance
and pass it as an additional argument to the `EventSource` like this:

```php
$connector = new \React\Socket\Connector($loop, array(
$connector = new React\Socket\Connector($loop, array(
'dns' => '127.0.0.1',
'tcp' => array(
'bindto' => '192.168.10.1:0'
Expand All @@ -70,9 +70,9 @@ $connector = new \React\Socket\Connector($loop, array(
'verify_peer_name' => false
)
));
$browser = new \Clue\React\Buzz\Browser($loop, $connector);
$browser = new React\Http\Browser($loop, $connector);

$es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
```

## Install
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
},
"require": {
"php": ">=5.4",
"clue/buzz-react": "^2.5",
"evenement/evenement": "^3.0 || ^2.0"
"evenement/evenement": "^3.0 || ^2.0",
"react/event-loop": "^1.0",
"react/http": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
Expand Down
19 changes: 10 additions & 9 deletions src/EventSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Clue\React\EventSource;

use Clue\React\Buzz\Browser;
use Evenement\EventEmitter;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\LoopInterface;
use React\Http\Browser;
use React\Stream\ReadableStreamInterface;

/**
Expand All @@ -20,19 +20,19 @@
* in order to handle async HTTP requests.
*
* ```php
* $loop = \React\EventLoop\Factory::create();
* $loop = React\EventLoop\Factory::create();
*
* $es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
* ```
*
* If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
* proxy servers etc.), you can explicitly pass a custom instance of the
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
* to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance
* to the [`Browser`](https://github.com/reactphp/http#browser) instance
* and pass it as an additional argument to the `EventSource` like this:
*
* ```php
* $connector = new \React\Socket\Connector($loop, array(
* $connector = new React\Socket\Connector($loop, array(
* 'dns' => '127.0.0.1',
* 'tcp' => array(
* 'bindto' => '192.168.10.1:0'
Expand All @@ -42,9 +42,9 @@
* 'verify_peer_name' => false
* )
* ));
* $browser = new \Clue\React\Buzz\Browser($loop, $connector);
* $browser = new React\Http\Browser($loop, $connector);
*
* $es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
* ```
*/
class EventSource extends EventEmitter
Expand Down Expand Up @@ -88,7 +88,7 @@ public function __construct($url, LoopInterface $loop, Browser $browser = null)
if ($browser === null) {
$browser = new Browser($loop);
}
$this->browser = $browser->withOptions(array('streaming' => true, 'obeySuccessCode' => false));
$this->browser = $browser->withRejectErrorResponse(false);
$this->loop = $loop;
$this->url = $url;

Expand All @@ -106,7 +106,8 @@ private function request()
$headers['Last-Event-ID'] = $this->lastEventId;
}

$this->request = $this->browser->get(
$this->request = $this->browser->requestStreaming(
'GET',
$this->url,
$headers
);
Expand Down
Loading