0

i am trying to make a websocket server in my wordpress plugin.

when i try to access the site it loads alot of time and outputs this iis error:

The FastCGI process exceeded configured request timeout

websocket server code:

$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server('127.0.0.1:9000', $loop);

$socket->on('connection', function (ConnectionInterface $conn) {
    $conn->write("Hello " . $conn->getRemoteAddress() . "!\n");

    $conn->on('data', function ($data) use ($conn) {
        $conn->close();
    });
});

$loop->run();

when i remove this code ^ it load fast and no error.

versions:

PHP: 7.2
ReactPHP: ^1.0 
Wordpress: 4.9.2
Neriya Rosner
  • 43
  • 1
  • 10
  • 1
    run it from cli, your not meant to init it from the browser. – Lawrence Cherone Sep 04 '18 at 16:32
  • @LawrenceCherone or everyone - is there a way to run it from wordpress? – Neriya Rosner Sep 04 '18 at 17:01
  • 1
    its possible but you would need to track whether an instance is already running, then you just need to fire off an ajax request to start it, then close the connection, and then hopefully not open the client socket connection till its started.. much more hassle then simply running from cli. – Lawrence Cherone Sep 04 '18 at 17:05

1 Answers1

3

Hey ReactPHP core maintainer here. Running any socket server including a websocket server is intended to run from the CLI or using supervisor/systemd. My suggestion would be to create such a special cli command in your plugin that you can call to start it. Doing funky magic with XHR requests is very error prone and not very stable. Alternatively if you absolutely cannot run cli commands is a service like pusher

WyriHaximus
  • 1,000
  • 6
  • 8