ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
913 stars 375 forks source link

./chatserver.php exits right after running. #99

Open ghost opened 7 years ago

ghost commented 7 years ago

I had to modify the first line to the path of php as follows

`

! /usr/bin/php7.0

<?php

require_once('websockets.php');

class ChatServer extends WebSocketServer {

protected function process ($user, $message) {
    foreach ($this->users as $u) {
        $message = htmlspecialchars($message);
        $this->send($u,$message);
    }
}

protected function connected($user) {

}

protected function closed($user) {

}

}

$server = new ChatServer("192.168.0.3","9000"); `

When I run it using ./chatserver.php

wh33t@wh33tserv:/var/www/html/d30/socketest$ ./chatserver.php Server started Listening on: 192.168.0.3:9000 Master socket: Resource id #6 wh33t@wh33tserv:/var/www/html/d30/socketest$

It just exits. I haven't modified anything else. What am I doing wrong?

Also, not sure why the formatting isn't working.

zelenko commented 6 years ago

Any idea why chatserver.php exits right after running?

root@lamp post/chat# php chatserver.php
Server started
Listening on: 192.168.1.3:9000
Master socket: Resource id #6
root@lamp post/chat#
ghedipunk commented 6 years ago

Based off of the information given?

No.

I have plans to add logging, but obviously that doesn't help right now.

I suspect that something is happening to the master socket resource between when it's created and when you get your first connection (or even actually listening for that connection), but that's pure conjecture on my part.

zelenko commented 6 years ago

Had to add this at the end of chatserver.php file.

try {
    $server->run();
  }
  catch (Exception $e) {
    $server->stdout($e->getMessage());
  }