-
-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http and pawl within same loop #75
Comments
I haven't used this personally, but this should absolutely be possible 👍 One of the core issues with your code is this subtle error here, which should likely fix most of the problems you're having: -$http->on('request', function ($request, $response, $connector, $loop) {
+$http->on('request', function ($request, $response) use ($connector, $loop) {
That's how you've coded this currently :-) You'll likely want to move to the connector call out of the request handler so that you only create a connection once instead of opening a new one for each incoming request. I hope this helps! 👍 |
Great. $loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$connector = new Ratchet\Client\Connector($loop);
$connector('ws://127.0.0.1:1338')
->then(function (Ratchet\Client\WebSocket $conn) use ($http) {
$conn->on('message', function (\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
echo "Empfangen von anderem Client oder dem Server: {$msg}\n";
//$conn->close();
});
$conn->on('close', function ($code = null, $reason = null) {
echo "Connection closed ({$code} - {$reason})\n";
});
$http->on('request', function ($request, $response) use ($conn, $http) {
print_r($request->getQuery());
if ($request->getMethod() == "POST") {
$param = $request->getQuery();
$conn->send($param['data']);
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end("Daten gesendet...\n" . print_r($request->getMethod()));
} else {
$response->writeHead(501, array('Content-Type' => 'text/plain'));
$response->end("Not Implemented!\n" . print_r($request->getMethod()));
}
});
}, function (\Exception $e) use ($loop) {
echo "Could not connect: {$e->getMessage()}\n";
$loop->stop();
});
$socket->listen(5000);
$loop->run(); |
Hey folks,
ist this possible? I want to expose a HTTP POST request and forward to Ratchet Websocket Server.
I would like in detail NOT open and close a socket connection with every POST. So the idea with one same loop.
Error:
Fatal error: Uncaught Error: Function name must be a string in http.php:22
Line 22 is:
$connector('ws://127.0.0.1:1338')
PS: Thanks for pushing PHP to the next level :-)
The text was updated successfully, but these errors were encountered: