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.
deleydSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deleydSoftware EngineerAuthor Commented:
Wow I didn't know I could code socket connections in PHP. Can you direct me to some PHP documentation on that?
deleydSoftware EngineerAuthor Commented:
I found lots of documentation on PHP Socket programming. (Didn't know that was possible.)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.