Websocket server won't connect if started via PHP

Clash 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.
networking users environment-variables php socket
add a comment |Â
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.
networking users environment-variables php socket
add a comment |Â
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.
networking users environment-variables php socket
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
networking users environment-variables php socket
asked 2 mins ago
Occam's Razor
1315
1315
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password