Skip to content

Instantly share code, notes, and snippets.

@cboden
Created May 10, 2014 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cboden/09e9a716ce64ff2a2b74 to your computer and use it in GitHub Desktop.
Save cboden/09e9a716ce64ff2a2b74 to your computer and use it in GitHub Desktop.
Account for expected errors
<?php
namespace MyNamespace;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class AccountedExceptions MessageComponentInterface {
protected $_app;
public function __construct($app) {
$this->_app = $app;
}
public function onOpen(ConnectionInterface $conn) {
$this->_app->onOpen($conn);
}
public function onMessage(ConnectionInterface $from, $msg) {
$this->_app->onMessage($from, $msg);
}
public function onClose(ConnectionInterface $conn) {
$this->_app->onClose($conn);
}
public function onError(ConnectionInterface $conn, \Exception $e) {
if ('Tried to write to closed stream.' !== $e->getMessage()) {
$this->_app->onError($conn, $e);
}
}
}
<?php
namespace MyNamespace;
$server = new Ratchet\App;
$server->route('/', new AccountedExceptions(new Ratchet\Server\EchoServer()));
$server->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment