Running Websocket directly in php class

Asked

Viewed 197 times

2

I am starting now with websocket, I have developed a chat in Realtime using the Ratchet library, I would like if there is any way to initialize the websocket without running command from the terminal.

I saw in the documentation the command:

<?php 

$app = new Ratchet\App('localhost', 8080);
$app->route('/chat', new MyChat);
$app->route('/echo', new Ratchet\Server\EchoServer, array('*'));
$app->run();

1 answer

1


For the development environment, the command is the simplest way to execute. You must somehow have the process running in parallel to listen to the requests sent.

An alternative would be to create an environment as if it were a production environment using supervisor, as pointed out in documentation of Ratchet.

  • I wanted the websocket running only when running the chat route, because I don’t think I would have to run it all the time. I’m sorry if I’m talking nonsense, but I don’t know much about websocket

  • They are two services running independently and interacting via http. Imagine that they are two servers on your machine. One is apache or ngnix for the web server that runs as a service. The webserver is running, whether you are using it or not. With the websocket is the same logic when running under the supervisor

  • Got it @gmsantos, liked the suggestion

Browser other questions tagged

You are not signed in. Login or sign up in order to post.