NotionCommotion Posted May 16, 2019 Share Posted May 16, 2019 I have the following socket server. <?php class Controller public function doSomething($conn):void { $foo=new SomeClassWhichDoesntExist(); } } require 'vendor/autoload.php'; $server = new \React\Socket\TcpServer($settings['url'].':'.$settings['port'], \React\EventLoop\Factory::create()); $server->on('connection', function (\React\Socket\ConnectionInterface $rawSocket) { $conn = new LengthPrefixStream($rawSocket); $conn->on('data', function($data) use ($conn){ $controller->doSomething($conn); }); $rawSocket->on('error', function($error, $conn) {exit('error';}); $rawSocket->on('close', function() use ($conn) {exit('close';}); $conn->on('error', function($error, $conn) {exit('error';}); $conn->on('close', function() use ($conn) {exit('close';}); }); $server->on('error', function (Exception $e) {exit('server error';}); Turns out Controller::doSomething() is trying to create a new SomeClassWhichDoesntExist, but since it doesn't exist, composer doesn't require it and then PHP throws an error. But the error is caught by FulfilledPromise::then(), and then appears to eventually be ignored and an exception is never thrown, and the loop continues. In the past, I've always been able to catch these errors, but must have changed something. Any thoughts what might have changed to prevent errors from being caught? namespace React\Promise; class FulfilledPromise implements ExtendedPromiseInterface, CancellablePromiseInterface { public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null) { if (null === $onFulfilled) { return $this; } try { return resolve($onFulfilled($this->value)); } catch (\Throwable $exception) { return new RejectedPromise($exception); //<===== Caught here } catch (\Exception $exception) { return new RejectedPromise($exception); } } } Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted May 16, 2019 Author Share Posted May 16, 2019 Don't know why, but I found a clue. If an error occurs in $controller->doSomethingOnData($conn);, then I catch the errors, however, $controller->doSomethingOnConnection($conn); goes uncaught. Fortunately, I don't do much in doSomethingOnConnection(). $server->on('connection', function (\React\Socket\ConnectionInterface $rawSocket) { $controller->doSomethingOnConnection($conn); $conn = new LengthPrefixStream($rawSocket); $conn->on('data', function($data) use ($conn){ $controller->doSomethingOnData($conn); }); }); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.