Reputation: 31
I am quite new to node.js programming. I am using linux dedicated server. I already have installed node.js in my server(linux).
I am using follwing php program to run the linux command so i can run node.js program by these linux command
test.php:
exec('node test.js &', $a1,$a2);
print_r($a1);
echo $a2;
And after running this program it showing following o/p:
Array ( ) 0
But not returns any value in $a1 variable where it should display "Hello World"
test.js:
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
I also tried with port 3000 and 8000.
Upvotes: 2
Views: 3659
Reputation: 8635
For once I cannot see how the same code runs on Windows, but not on Linux. Especially since your php contains UNIX syntax.
Please do not use PHP as a bridge to Node.js, it just kills all the point of having Node.js in first place.
What you need to do is run a command in the Shell of that linux machine:
node test.js
It will start a process, do not exit it.
Once the process is running, you shall be able to navigate to your Hello World
through a browser, the URL will be based on your Server's IP and port you chosen, example:
http://1.2.3.4:8888/
If that does not answer your question, then clarify please, on what exactly you want to achieve.
Upvotes: 3