Someone Could tell me how start node function from PHP. For example I want to load some data from node http request and load it to PHP website. Please put any tutorials or part of code.
Asked
Active
Viewed 106 times
2 Answers
0
You could use php's exec
- http://php.net/manual/en/function.exec.php - just so long as you are not using any user input in your command. I don't know of a tutorial for this.
Here is a SO on the different ways to make calls to your system: PHP - exec() vs system() vs passthru()
-
My application is enabled, and has na few functions. I want to call for example to `app.loadData()` and get json data. I do not want turn on the application because it is already enabled but only execute one function from them and display it on website. – Jensej Mar 11 '16 at 16:45
-
there is no way of that I know that you can call a node method from inside php (basically, execute node code in PHP is what it sounds like you're trying to do). You'll have to make a node executable file that runs your method, then take the output and do something with it in PHP. That's all I know - maybe someone knows another way. – dmgig Mar 11 '16 at 16:47
0
Your node.js code should run a simple http server listening on the loopback interface, so your php code can request the data using a http request.
Another option is to run the node server on a public url (on a different port or using a reverse proxy) and let it return data using JSONP.

Anatol - user3173842
- 1,385
- 1
- 12
- 16