How do I use Node.js to run a PHP page?

Asked

Viewed 1,425 times

2

My case is the following: the microcontroller sends data using GET to the server, it saves it in the Mysql database and tests if it needs to trigger the alert. This alert is made with a PHP page that uses jQuery+Ajax to send to another server, this already works, however, it needs a browser to run the jQuery application because it is on the client side and is not possible with the microcontroller. I searched and saw that it would be the case to use Node.js to process this on the server side. Here’s the question: how I would run this PHP page for Node.js?

  • Why are you mixing Node and PHP? have to be or think the solution goes there?

  • In fact it is because this page is already working, is ready and the deadline is short. As I have no experience with Node.js, Alvéz would be less worse for now to make it "browser" to work jQuery functions on the PHP page.

  • I’m still lost..., do you have a server running with Nodejs or PHP? I don’t understand what you mean by navegador and microcontrolador (Maybe they are terms that I am not used to in Portugal). If you have the page running in Nodejs put here the code you have and di what you need to do. Explains the functionality better to understand the whole problem.

  • When I say browser, I mean a browser. The microcontroller I’m using is the Arduino with an Ethernet Shield W5100. The path is as follows: Arduino -> PHP server -> Mysql. But on the PHP server it will do some tests on the received data, if it enters the condition, IE, need to trigger the emergency command would be as follows: PHP server (using jQuery+Ajax) -> Another server. Arduino as Client does not run this page with jQuery, it would work if it ran on the server side with Nodejs, but it could run this PHP page?

  • 1

    I don’t think Nodejs is the right tool for what you want. If you explain your structure better (what runs in each place and what you want to result) maybe someone can help.

  • Looks like what you need is a headless browser, like http://phantomjs.org/. But I don’t know if you can run this on an Arduino, I would guess that it doesn’t work.

  • Bruno what do you mean by "PHP server (using jQuery+Ajax)"? Do you know that jQuery is a client-side library right? If you can join code you want to run, or this PHP page you want to run for the question get more concrete.

  • Vote today! Vote tomorrow! Vote always! Vote consciously! Your vote is very important to our community, contribute to us, and help make Stack Overflow in Portuguese (Sopt) bigger and bigger. You can learn more at: Vote early, vote often

Show 3 more comments

1 answer

0


for Node to run the page I see no problem, you simply configure it, run the script that makes the call from php and end, but I think the most elegant solution is to make php itself calling itself ( all on the server side )

I have a case like this here, I get information via SOA like php that writes in my mysql, before I had to stay with an open browse and the page that made the data collection there, the script had a recursivity p/ call the page again every 30 sec.

well now I have made in shell-script a "process" that makes this service p/ me

#php arquivo.php &

this & is important as it will ensure that the process is running even if you close a session

if you want to know more about the nodejs https://nodejs.org/ has the steps of how to configure it, it is javascript, from there p/ front just call your php page recursively from the same result however, it is an extra installation/ configuration in my point of view.

( use nodejs in other cases like socket, warn system browsers that an event has been run and browsers go on to perform a certain javascript instruction, chat is another example etc. )

  • Thank you very much, Maison. The problem was where the processing was done, could not be on the client side but already had the page ready, so I thought to use Node.js, but I solved even using Curl in PHP itself. It’s not that fast, that’s remarkable, but it works. I can do the listing, all the tests, validations, save to the database and send the information, all being processed on the server side.

  • @Brunomacedo could thank me with his little vote also right =D just don’t feel obliged...rsrsr

Browser other questions tagged

You are not signed in. Login or sign up in order to post.