• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

From PHP to C++?

I have a device on the internet. It has a MAC address. I would like to communicate with this device. The device accepts short commands, and returns data.

I would like to communicate with this device from a web browser. I can write HTML or PHP, or even CGI if necessary.

Problem is XmlHttpRequest doesn't allow cross domain access, and this device knows nothing about JSONP.

I do have a C++ program which can communicate with the device over the internet. It runs as a web server, and does a lot of low level socket I/O. It accepts user browsers connecting to it, via a certain port number, and it connects to the device, and it shuffles the data back and forth between the device and the user, formatting the data into HTML, sending the formatted HTML to the user's web browser.

Question: If I write a website in PHP, is there some way I can jump from PHP code into this C++ code?

Or, is there a way I can do this the other way around: run PHP code from within the C++ program? Right now the C++ program knows nothing about PHP or what to do with such files. We do have Apache installed. Not sure how to send it a PHP file for processing from a C++ program.
  • 2
2 Solutions
käµfm³d 👽Commented:
It accepts user browsers connecting to it, via a certain port number, and it connects to the device
If that be the case, then I suspect you would want to use cURL (or similar) to send calls to this web server application. Your PHP can still expose endpoints that your JSON would hit, but under the hood the PHP would use cURL to communicate with the device. Have you looked into cURL at all?
Julian HansenCommented:
Depending on how complex it is you can also code the socket connet from PHP as well. Basically port your C++ code to PHP (there are some similarities so might not be too difficult depending on the complexity of the C++ code).
deleydAuthor Commented:
Wow I didn't know I could code socket connections in PHP. Can you direct me to some PHP documentation on that?
deleydAuthor Commented:
I found lots of documentation on PHP Socket programming. (Didn't know that was possible.)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now