Websocket server won't connect if started via PHP

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have a websocket server written in Node. The following instruction, when executed from the command line starts the websocket server successfully:



nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &


I can see that the server is running because pgrep -x "bm-server" displayes the PID.



I know the port is open and listening because # netstat -an | grep ":1337" produces:



tcp6 0 0 :::1337 :::* LISTEN



I know the port is accessible because telnet myhost 1337 successfully connects from another machine.



And my web app can connect to and use the server as expected.



The problem is that I want to start the program via PHP:



exec('nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &', $stdout, $exitcode);


That command, when run from PHP passes all the same tests as above, except when connecting from the browser. I can connect with telnet just fine, but when I try to connect from the browser I get failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED



It has to have something to do with the environment in which PHP executes the code. I can't figure out what could possibly be affected by that in the script though.



Here's the source for the server, if it mattters.



What is the problem with the PHP user (www-data) starting the server? BTW I also gave www-data permission to run sudo without a password and tried it with sudo as well, but that didn't make a difference.









share

























    up vote
    1
    down vote

    favorite












    I have a websocket server written in Node. The following instruction, when executed from the command line starts the websocket server successfully:



    nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &


    I can see that the server is running because pgrep -x "bm-server" displayes the PID.



    I know the port is open and listening because # netstat -an | grep ":1337" produces:



    tcp6 0 0 :::1337 :::* LISTEN



    I know the port is accessible because telnet myhost 1337 successfully connects from another machine.



    And my web app can connect to and use the server as expected.



    The problem is that I want to start the program via PHP:



    exec('nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &', $stdout, $exitcode);


    That command, when run from PHP passes all the same tests as above, except when connecting from the browser. I can connect with telnet just fine, but when I try to connect from the browser I get failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED



    It has to have something to do with the environment in which PHP executes the code. I can't figure out what could possibly be affected by that in the script though.



    Here's the source for the server, if it mattters.



    What is the problem with the PHP user (www-data) starting the server? BTW I also gave www-data permission to run sudo without a password and tried it with sudo as well, but that didn't make a difference.









    share























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a websocket server written in Node. The following instruction, when executed from the command line starts the websocket server successfully:



      nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &


      I can see that the server is running because pgrep -x "bm-server" displayes the PID.



      I know the port is open and listening because # netstat -an | grep ":1337" produces:



      tcp6 0 0 :::1337 :::* LISTEN



      I know the port is accessible because telnet myhost 1337 successfully connects from another machine.



      And my web app can connect to and use the server as expected.



      The problem is that I want to start the program via PHP:



      exec('nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &', $stdout, $exitcode);


      That command, when run from PHP passes all the same tests as above, except when connecting from the browser. I can connect with telnet just fine, but when I try to connect from the browser I get failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED



      It has to have something to do with the environment in which PHP executes the code. I can't figure out what could possibly be affected by that in the script though.



      Here's the source for the server, if it mattters.



      What is the problem with the PHP user (www-data) starting the server? BTW I also gave www-data permission to run sudo without a password and tried it with sudo as well, but that didn't make a difference.









      share













      I have a websocket server written in Node. The following instruction, when executed from the command line starts the websocket server successfully:



      nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &


      I can see that the server is running because pgrep -x "bm-server" displayes the PID.



      I know the port is open and listening because # netstat -an | grep ":1337" produces:



      tcp6 0 0 :::1337 :::* LISTEN



      I know the port is accessible because telnet myhost 1337 successfully connects from another machine.



      And my web app can connect to and use the server as expected.



      The problem is that I want to start the program via PHP:



      exec('nohup "/root/.nvm/versions/node/v8.11.1/bin/node" "/var/www/bm-server/bm-server" 1337 > "/var/www/bm-server/logs.txt" 2>&1 &', $stdout, $exitcode);


      That command, when run from PHP passes all the same tests as above, except when connecting from the browser. I can connect with telnet just fine, but when I try to connect from the browser I get failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED



      It has to have something to do with the environment in which PHP executes the code. I can't figure out what could possibly be affected by that in the script though.



      Here's the source for the server, if it mattters.



      What is the problem with the PHP user (www-data) starting the server? BTW I also gave www-data permission to run sudo without a password and tried it with sudo as well, but that didn't make a difference.







      networking users environment-variables php socket





      share












      share










      share



      share










      asked 2 mins ago









      Occam's Razor

      1315




      1315

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477997%2fwebsocket-server-wont-connect-if-started-via-php%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477997%2fwebsocket-server-wont-connect-if-started-via-php%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)