开发者

Pinging a Node.js server from PHP on AWS

开发者 https://www.devze.com 2023-02-14 06:42 出处:网络
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:

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.

Pinging a Node.js server from PHP on AWS

I tried stopping httpd a开发者_如何学运维nd 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


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.


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


have you tried using your server's IP address (instead of 127.0.0.1) in the createServer.listen() call?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号