0
People are studying websockets, and when trying to follow several examples found on the internet and on the site of Ratchet itself I just can’t run the server, the terminal is like this:
Follow code from the example I used:
Chat.php
<?php
namespace MyApp;
require dirname(__DIR__) . '/vendor/autoload.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
public function onOpen(ConnectionInterface $conn) {
}
public function onMessage(ConnectionInterface $from, $msg) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
chat-server.php
<?php
require dirname(__DIR__) . '/src/Chat.php';
use Ratchet\Server\IoServer;
use MyApp\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new Chat(),
8080
);
$server->run();
I came to think it would be because of the 8080 port, but I’m doing the tests on my computer locally. What I’m doing wrong?
It is running. When you turn the remote
php arquivo.php
the terminal will be "paused" until this task is done. Run the command again and make a connection via client. If you want to free the terminal for other tasks, just run the commandphp -f nome-do-arquivo.php &
– Valdeir Psr
I understand, but then in case I implement an application based on a websocket server using Ratchet I need to leave the terminal open? or is there any way you can keep it running in the background constantly? @Valdeirpsr
– Leandro Silva Campos
To leave a lawsuit in
background
, just rotatenohup php -f nome-do-arquivo.php &
and for the code to always run when starting/restarting the server, just create a shell script in/etc/init.d
– Valdeir Psr