c++ client with php monitoring server - php

I'm trying to make a simple project. first i will make a simple c++ client, it function is generate a random string and ID. Then if I run the c++ client, and if I look in the php server, it will just show this ID is online, then the php server will send request to c++ client to get the random string, then the c++ will send it to the php. I do have some basic knowledge in c++ and php, but I don't know how to do this kind of stuff. I hope someone can guide me to the correct learning path, or just tell me what should I learned to accomplish this simple project. Thanks.

Start with learning sockets (here for example), such you can build a c++ client \ server.
PHP gets requests by GET and POST methods, i suppose you know it.
It's all you need.

Related

How to integrate C++ application into PHP website?

I have a c++ application that processes a sentence and responds back to the respective user. I have a website using php that I would like to post data to this application and receive this response. Ideally, the C++ would run on the webserver and not have to be fully loaded each time it is used, but i haven't been able to get a simple 'hello world' (with cgi or c++) to work on the webserver.
What would be the easiest way to integrate a c++ application into a website? Should this work with any webhost?
To Integrate them you can take two approaches.
1) Integrate C++ as a function into PHP with http://www.php-cpp.com
You can create a function, say my_complex_function, that when called in PHP, will execute a C++ code. You can read the site's documentation for information about it.
2) Keep them separate and communicate through HTTP/Pipes/Sockets/Other
You could build a C++ daemon that opens up some kind of communication interface like a Socket, then with PHP you open a socket to it, send the information through the socket, and receive the answer there too.
You can find socket examples for PHP here: http://php.net/manual/en/sockets.examples.php

Using PHP and C++ for data exchange?

Is it possible to send data from C++ to PHP? I have wrote a server in C++ that connects to a database, and I was wondering if it is possible at all to use the socket library built into PHP to connect to the socket server written in C++. Would it just be PHP itself? I mean, would I not use JavaScript (AJAX) to call a PHP script that might do the socket work?
Basically, how do Google do this? I know some of their applications use C++/Java as their back-end, but is there any performance at all?
For those wondering why I am asking this question, then the answer is I don't want to rely on PHP to handle data as I am writing a game. I would like PHP to handle the web part, but not necessarily the game client so-to-speak; and I just think C++ would be a lot efficient at sending and receiving data to store in the database.
Has anyone done something like this and if so did you run into problems; and is this a practical solution at all?
Thanks.
Google use protocol buffers for data exchange between different services. Facebook has Thrift. Etc, etc. There's a plenty of protocols and libraries for you to choose from, but I'm afraid you'll have to do the research yourself.
Last time we had such a task (connecting C++ backends with PHP frontend), we wrote our own, very simple protocol. It's not that hard, in fact, it might be easier than implementing some abstraction on both sides.

PHP client communicate with C++ Server over TCP

Im trying to get a Php page to be able to communicate with a C++ server. It must be able to recive and send at all time (and the same time). When the php page recives a string it shall make some changes in Mysql db but at the same time send other strings to the server.
You can think of it as a chat, but then the php recive a string it shall be formated.
The C++ server is up and running only the php client side is a mystery for me.
Is there any example code that anyone can help me with?
Thx!
Well first of all you need to understand and remember that PHP in itself is stateless. You can have PHP receive a request and parse it and do something with the gained information, but after that the request closes.
One solution you could try is having your C++ app HTTP POST to a PHP script. This script can parse and analyze the request and take action upon it.
Store something in the database
Create a response
Output the response
The C++ app can then do something with the response.
This will work but if your actual use case is a chatroom or something of the likes there are better solutions than using PHP.

Does GWT support php?

does GWT support php ?
Useful links:
http://www.ibm.com/developerworks/xml/library/x-gwtphp/ (07 Apr 2009 )
and
http://www.gwtphp.com/
http://sourceforge.net/projects/gwtphp/)
http://code.google.com/p/gwtphp/
Havent used, so I can't tell if it's any good
To a certain extent, yes.
The heart of GWT is some magic for converting Java source code for a Web client into JavaScript. There's no wiggle room there; it's either Java or nothing.
But a GWT-translated client can interoperate with a server written in any language. You'd be missing out on some of the special remote calling capabilities offered by the GWT framework, but if you're willing to transfer XML or JSON back and forth, a PHP-based server could work with your Java/JavaScript-based client.
Yes, GWT completely supports PHP. Write your PHP script and use request builder to make the ajax call, then make your PHP return JSON data and use JSON parser within GWT to parse your JSON.
Normally, when you create a GWT application, it runs with the default java server, to direct it to your php server, use the following,
noserver -remoteUI "${gwt_remote_ui_server_port}:${unique_id}"
-startupUrl <name>.html
-logLevel INFO -codeServerPort 9997
-war /opt/lampp/htdocs/../war com.<appname>.<appname>
if ever you are using eclipse, simply place the app on your php server you are using

Calling a Python program from PHP

I've got a version of the A* algorithm that builds a graph of the
UK road and cycle network in Python lists. It takes about 30 seconds
to initialise, but once done can very quickly find the shortest route
between any two vertices. The start and finish vertex ids are provided
by PHP.
I'm trying to work out the best way of communicating between
PHP and the Python program. I only want to do the initialisation phase
when the Apache server starts, so my question is: How do I keep the
python program alive and request routes from it via php? I have a
GLAMP setup.
Easiest way that I can think of would be XMLRPC. Python makes it horribly easy to set up an XMLRPC server, and there's php_xmlrpc for bindings on the PHP side...
def calculate_path(v1, v2):
return [v1, ..., v2]
from SimpleXMLRPCServer import SimpleXMLRPCServer
server = SimpleXMLRPCServer(('localhost', 9393))
server.register_function(calculate_path)
server.serve_forever()
and you're running and should be able to do an XMLRPC call for calculate_path on http://localhost:9393/ from your PHP app.
Check this question out: Calling Python in PHP
Also check out this extension: http://www.csh.rit.edu/~jon/projects/pip/
I don't know if you're hosting environment allows you to add new php extensions, but you get the idea.
I would make a "backend" server from your Python application. There are many ways to call into the Python application:
Thrift and protocol buffers
HTTP (CherryPy is simple to get cranking) with XML or JSON
XMLRPC in Python
Raw sockets
This avoids any startup penalty for the Python application.
You could do something as simple as a REST web server in Python using web.py:
http://webpy.org/
and then call that via PHP, should make the whole task super simple.
See this for more info:
http://johnpaulett.com/2008/09/20/getting-restful-with-webpy/

Categories