0
I’m trying to use the Ratchet to create WebSockets
in PHP
on a site I own. When I did the tests (localhost
) everything worked perfectly, but when I try to put online, it does not run the connection. Reading more on the subject, I saw that it would be necessary to change the ip
to be the server one - or use the correct reference. Which led me to this final code:
var socket = new WebSocket('ws://meusite.com.br:8000');
But when I access the site, after a while, I get this message:
failed: Error in Connection establishment: net::ERR_CONNECTION_TIMED_OUT
The server file kept this code:
require __DIR__ .'/../vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\http\HttpServer;
use Ratchet\WebSocket\WsServer;
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
), 2000, '0.0.0.0'
);
$server->run();
I’m using composer
also for package management Ratchet
.
I don’t know what could be happening to not having the connection or what I missed, but this process is not working online, only at localhost
.
Editing the question, and already adding the answer to the comment, I have access SSH
yes, even when I try to start the script as done in localhost
php bin/server.php
The SSH
presents the following error:
Fatal error: Class 'Ratchet http Httpserver' not found in /bin/server.php on line 10
Note: The final application will not be a chat, I’m doing so just by following a tutorial. The goal is that there is only the exchange of messages to inform that a new order has been made, or that a new service order has arrived, etc...
But do you have SSH access to your server to fire the application, or do you have a webapp system to set up a PHP application? websocket does not run directly on Apache or Ngnix, it is independent, it will not work if you access via
http://site/script.php
, unless you use theexec();
, however I’m almost sure it will take privilege to start Websocket.– Guilherme Nascimento
@Guilhermenascimento had forgotten this stage, I edited the question. But yes, I have access and tried to boot as done on localhost, but still it presents an error.
– celsomtrindade
Spun the
composer update
? Tell me one thing it wouldn’t be rightrequire __DIR__ .'/vendor/autoload.php';
? Places the folder structure– Guilherme Nascimento
@Guilhermenascimento I believe require is as it is, because from the root I have 2 folders
bin/server.php
andvendor/autoload.php
. Within the vendor there are also other folders such as Ratchet, Composer, etc.. But I didn’t ask Poser update, and when I tried it now, it presented an error stating that there was no permission or it was not in a directory that I have permission for (something like this)– celsomtrindade