Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinging a Node.js server from PHP on AWS

I have a long procedure I have written in node.js, but I'd like the PHP side of my application control kicking it off. My node is something like:

var http = require('http');

http.createServer(function (req, res) {
  console.log('Got request')

  try{
    doProcedure()
  } catch(e) {
    console.log('Really bad error while trying to do the procedure:')
    console.error(e.stack ? e.stack : e)
  }

}).listen(8124, "127.0.0.1");

When I run this on my local machine, http://localhost:8124 will trigger things correctly. On aws, I've added the 8124 port but requests to mydomain.com:8124 aren't picked up by node.

Port settings in AWS

I tried stopping httpd and then letting node listen on port 80, to rule out ports not being forwarded correctly, but it still saw nothing.

So two questions, I guess:

  1. How to get Node listening as a daemon, so I can pass over requests? ("update user x", "update user y", "update all users", etc)
  2. How do I ping that daemon from php to start these procedures in an AWS evironment?

Bonus question: Is there a better way I should be doing this?

Thanks all,
~Jordan

like image 659
Jordan Feldstein Avatar asked Mar 03 '11 00:03

Jordan Feldstein


2 Answers

If you omit the second argument to listen(), node will listen on all IP addresses. That way you can run the same code locally to test and also on your EC2 instance.

In your catch block, you might also want to send back an HTTP error response to the client.

like image 119
Matt Ranney Avatar answered Oct 19 '22 10:10

Matt Ranney


you should have a 10.* ip iirc for aws, your elastic/dynamic ip cant be bound to

like image 27
jmoon Avatar answered Oct 19 '22 09:10

jmoon