PHP Websocket possibly not going through Cloudflare at all?

356 views Asked by At

I'm currently using Ratchet PHP Websockets example code (http://socketo.me/docs/hello-world) and when I try to run the Websocket it doesn't output anything but does show that it's "live".

On my website I'm using the very same JS code as the example except using wss:// as my website is going through Cloudflare's SSL. Now my question is, when I try to connect to the websocket, in my Chrome developer tools it just continuously shows pending and will terminate if I turn the websocket off.

I cannot find a way to debug what is going on with it, I'm using the ports that Cloudflare allows me to use (which is :8443) and I am on a plan where Websockets are supported by Cloudflare. But I cannot seem to find any answers about using Websockets through cloudflare and when I turn on error_reporting it doesn't seem to output anything either.

Is it something with Cloudflare? When I type php runwebsocket.php is it supposed to output something besides nothing?

When I used this script for the Websockets (https://github.com/ghedipunk/PHP-Websockets) it would output if a client has connected to the socket but would still give me the same issue where it's not actually fully connecting to it.

EDIT: When I go to the Websocket Echo testing site when I try to connect to my socket it just doesn't output anything either.

**EDIT #2:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

require('vendor/autoload.php'); // composer require cboden/ratchet

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use AppSocket\Notifications;

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Notifications()
        )
    ),
    8443
);
$server->run();

Code for AppSocket\Notifications

<?php
namespace AppSocket;

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Notifications implements MessageComponentInterface {
    protected $clients;
    public function __construct() {
        $this->clients = new \SplObjectStorage;
    }
    public function onOpen(ConnectionInterface $conn) {
        $this->clients->attach($conn);
        echo "New connection! ({$conn->resourceId})\n";
    }
    public function onMessage(ConnectionInterface $from, $msg) {
        foreach ($this->clients as $client) {
            if ($from !== $client) {

                $client->send($msg);
            }
        }
        echo "Yay";
    }
    public function onClose(ConnectionInterface $conn) {

        $this->clients->detach($conn);
        echo "Connection {$conn->resourceId} has disconnected\n";
    }
    public function onError(ConnectionInterface $conn, \Exception $e) {
        echo "An error has occurred: {$e->getMessage()}\n";
        $conn->close();
    }
}
0

There are 0 answers