Answer the question
In order to leave comments, you need to log in
How to make websocket work in php without running server via console?
It is necessary to make real time chat in php. I'm thinking of using laravel bootstrap angular and Ratchet library to create real time bi-directional php applications using websocket. The problem is that in the ratchet documentation, when creating such an application, it is necessary to run a script from the console, which, as I understand it, starts the ws server. push-server.php
file :
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new MyApp\Pusher;
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8080, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
$ php bin/push-server.php
Answer the question
In order to leave comments, you need to log in
We just set up the same supervisord that will start / restart the process.
but how to do it on hosting is not clear
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question