954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php to c++?

Hello!

I was wondering if it were possible for me to have a PHP script which would send a line of charactors to my C++ program. The C++ program needs to run all the time to recieve the inputs from PHP. Both the C++ program and my webserver is on the same machine(localhost).

So -> I was thinking on sending a socket to my C++ program and then do a "if" statement to check if it knew the socket, checking agianst predefined stuff and if it regonizes something, it would do a block for that match.


- realchamp.

realchamp
Newbie Poster
22 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

There are a couple of ways to do it that pretty easy. If you're using the socket approach you can just have PHP open a client socket and send data to the C++ app. The other way is just to have C++ poll a file that PHP writes to. The latter is quite expensive but easier to implement.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 
There are a couple of ways to do it that pretty easy. If you're using the socket approach you can just have PHP open a client socket and send data to the C++ app. The other way is just to have C++ poll a file that PHP writes to. The latter is quite expensive but easier to implement.


Hmm the first one sounds like something I'd like to have, do you have any tutorials for that? (Both PHP and C++)

realchamp
Newbie Poster
22 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 
Hmm the first one sounds like something I'd like to have, do you have any tutorials for that? (Both PHP and C++)

http://php.net/sockets

For C++ you might want to look around for forums, there's bound to be a link to a good one. If not, just google C++ sockets there is a veritable shit-ton

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

http://php.net/sockets

For C++ you might want to look around for forums, there's bound to be a link to a good one. If not, just google C++ sockets there is a veritable shit-ton


Alright thanks for the quick answer!

And does the PHP need to run the socket server or are the C++ app supposed to do that?

Both should be able to send back and forward. The C++ program just needs to send basic status reports.

realchamp
Newbie Poster
22 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Alright thanks for the quick answer!

And does the PHP need to run the socket server or are the C++ app supposed to do that?


Based on what you needed it would make sense for the C++ app to listen (be the server) and PHP to send the data to the server (client)

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 
Based on what you needed it would make sense for the C++ app to listen (be the server) and PHP to send the data to the server (client)


Okay. Thanks so much!

-- realchamp.

realchamp
Newbie Poster
22 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You