Running socket.io on shared Hostmonster servers

I am planning a small hobby project that will use node on Hostmonster. Now I know that Hostmonster is for Apache, but I decided to use node.js, constantly using pm2 and manually compiling node. Thus, simple restAPI requests work.

those.

  • I am running the node server on localhost: 3000
  • I have a link on the server //relay.example.com/r.php?arg1=val
  • GET requests that fall into this URL are passed as such
$fp = fsockopen("localhost", 3001, $errno, $errstr, 5);

if (!$fp) {
  echo "Error: $errno - $errstr";
} else {
  $out = "GET / HTTP/1.1\r\n";
  $out .= "Host: localhost\r\n";
  $out .= "Connection: Close\r\n\r\n";
  fwrite($fp, $out);
  while (!feof($fp)) {
    echo fgets($fp, 128);
  }
  fclose($fp);
}
  1. Node / express request and send a response through res.send

Websockets! (GET/POST) socket.io, . , apache (, , - ProxyPass, hostmonster - , - .

php relay script (fsockopen) node , . , .

, , socket.IO, .htaccess websocket node .

, / Hostmonster, !

+4

Source: https://habr.com/ru/post/1629641/


All Articles