PHP client communicate with C++ Server over TCP - php

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.

Related

IIS with PHP: How to get the data from a SOAP envelope?

An external application is calling my PHP script and passing URL parameters and a SOAP envelope. I can access the URL parameters in the $_GET array. However I cannot access the SOAP envelope. I was expecting it in the $_POST array, but that is empty.
The IIS log clearly shows that the SOAP envelope is being received by IIS but somehow I cannot access it in PHP - or I am using the wrong methods/variables.
When I check the "failed requests log" in IIS, I see the SOAP data as "GENERAL_REQUEST_ENTITY".
However I am at a loss when trying to access said data from within my PHP script. Is this kind of content stored in a different variable (other than $_GET, $_POST or $_REQUEST)? Or is IIS not forwarding this to my script and if so, why not?
Edit: I am not tied to PHP if PHP is not capable of doing this, I am open to any language that gets the job done. However my knowledge of ASP.NET is more limited than that of PHP. Is there a better language for capturing the missing data from the request?
This problem is not going away and I need to find a solution. So far no matter how much I search via Google, I keep running into dead ends.
Edit #2: Here is a screenshot of the log file for clarification. It clearly shows the XML and so does Fiddler, which I have also just now tested:
How can I capture this XML with PHP (or ASP.NET for that matter)?
Best regards
Max

Receive JSON POST data in ZK 6

I am writing an application that will send JSON data via POST with PHP cURL and then the data will be read by ZK 6 application and processed, how can I achieve this? Thanks.
[Edit]
I wanted to create a web service.
Since ZK applications are running in a Servlet Container (e.g. Tomcat/Jetty) you can just create/configure an HttpServlet implementation in your web.xml and post data to it using any kind of HttpClient ... be it a browser or a command line tool such as cURL or from PHP code.
From a ZK perspective however this doesn't seem to make much sense yet with the given information. A ZK application is running in a browser and depends on an HttpSession.
What you didn't tell is, where your application is currently running ... in an IFrame or in a headless browser at server side? Where do you want to send the information? To the overall application or a specific Session or even specific browsertab?

How to call PHP from MATLAB?

I have some analysed data in MATLAB which I need to send to a server. I have a php link to access the server. Any idea how to call php from MATLAB?
Thanks.
If you will frequently send data back and forth between MATLAB and your web server, perhaps you can consider using SaturnAPI. SaturnAPI provides a REST interface for your Matlab and Octave scripts, so that you don't have to install anything on your own server. It can even send Base64 encoded 3D plots to you. Here is the demo. Below is a diagram showing that you can pass inputs to the script via the SaturnParams variable in the HTTP call.
Disclosure: I work on SaturnAPI

c++ client with php monitoring server

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.

How to update a webpage (only) when something changed on the server side

I have a simple php page that displays data from a mysql database. I want it to update itself automatically when data gets changed on the server. (I don't want to update the page periodically at fix time intervals.) I guess I need the technology behind FB chat box or omegle. But I don't know how to implement it on php and mysql. I would be grateful if you could help me. Thanks.
You would need to look into WebSockets or a Comet server (which uses long-polling techniques) to accomplish a push system. Alternatively, instead of using push-like notification, you could make frequent polls to the server with nothing more than a request identifier and a timestamp, let the server decide if there is anything new since the last poll, and serve up the data if there is.
you can implement Comet technology which is opposite of Ajax. JavaScript Dojo Toolkit can be useful to handle this method well.
Dojo WebSocket
http://dojotoolkit.org/features/1.6/dojo-websocket
http://cometd.org/
"Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it."
http://en.wikipedia.org/wiki/Comet_(programming))

Categories