How can i call a node.js method from PHP

1,286 views
Skip to first unread message

Amrit Kumar

unread,
Mar 19, 2016, 10:26:28 AM3/19/16
to nodejs
I am working on a GPS tracking system and have used node js module available for gps tracking.  i would like to understand how i can call method from my  web interface developed in Php to the node.js   server so that  the node.js server can further send the command to the GPS device on tcp . 





Denard Springle

unread,
Mar 20, 2016, 12:11:12 AM3/20/16
to nodejs
Lots of different ways...

  1. expose an API using Node.js for your PHP web app to call (e.g. build a REST API around the GPS module)
  2. if node and PHP are on the same physical server, and it is a low use (e.g. under 20 concurrent users) system, you could write a file in PHP and have Node look (directory watch) for that file to read and execute whatever commands are in the file.
  3. you could use a 3rd party cache, like ehCache, to store commands from PHP and read (poll for) them from Node.
  4. you could also do that with a database (store record in PHP, read (poll for) the record in Node.
  5. Ditch PHP altogether and build the webapp in Node.
That's just 4 off the top of my head :) If it were me, I'd build a REST API in Node and call it from PHP - it's the cleanest of the solutions if you're tied to PHP for your webapp. Otherwise, just write the webapp in Node as well.

HTH!

-- Denny

Kevin "Ingwie Phoenix" Ingwersen

unread,
Mar 20, 2016, 1:20:25 AM3/20/16
to nod...@googlegroups.com
Or use hprose. An RPC protocol that can communicate between Node and PHP. I use it in my own project to forward unhandled HTTP traffic from node to PHP to run a traditional Laravel app.
Reply all
Reply to author
Forward
0 new messages