PHP communicate with program - c#

I'm currently planning on a project I want to work on. These are the steps:
User visits the website and searches for a name
PHP sends a command to a C# or Java program
Program sends JSON data back to the website
PHP saves data to MySQL and shows data to user
I'm trying to research what I need to do to make this work. I just need advice on what to search for to learn. How do I make PHP and the program communicate? Should I look into servlet? Any advice on doing the steps more efficient like making the program query the database instead.

Personally, I'd prefer Web-Service for your situation. you can design a Web-Service method for C# or Java , these mechanism provides a platform for your PHP application ( or another applications ). the PHP application only call the Web-Service methods. WS method perform the search and return the result. then you can process the result and do whatever you want.

Do this by database. Make a java thread scheduler which seance a database table each time. Now whenever PHP receive a request then it will insert that request into database with a new flag, now Java thread which is sensing the database will pick the request from database and process that and after processing will put the response into database , now PHP can pick that response and send back to USER.

May be you can use shell_exec from PHP to communication with C# or Java
Please read PHP Manual for using shell_exec

Related

Creating webplugins

I am trying to create a program that will be passed input data from events a user fires from a webpage on their browser. I am aiming at google-chrome currently with the program being in either java or C#. I know this is possible because Spotify does this, so does the Battlefield 3 PC gui. How can I go about doing this? Does the user need to install an extension or can I get that information straight from google-chrome? Note: The webpage is not being run on localhost.
You're going to want to look into web sockets. Web sockets are just cool. I got a huge grin on my face the first time I got demo working. :D
Here's a tutorial that helped me out:
http://www.developerfusion.com/article/143158/an-introduction-to-websockets/
You can create a socket listen in your appilcation then connect to it from javascript, passing whatever data you desire. It's nicer then ajax as it's a persistent open connection and you don't have the overhead of http calls.

Send Data From PHP to C# or VB.NET

Today'm trying to pass a variable and an array of PHP to a desktop application, but I have no clue how to do it.
To be more precise in my question I need PHP run the Desktop Application Developed in C # or VB.NET and send a variable.
If anyone can help me with some solution,suggestion or method is welcome Thank You.
You should send the information to the client in a format you can parse client side. XML would be one example.
So if you go the XML route (I'd look for a better transport data structure)
PHP outputs XML when the client application requests the data
The client then parses the XML pulling the data from it and storing it as a native data structure
Given your clarification in your comment (that you want to do this on the client machine), the answer is you can't. PHP doesn't run on the clients machine, it runs on your server and outputs to the clients browser, the browser then interprets that and displays the results, the browser doesn't run other applications as that is asecurity breach...except when downloading certain mime-types. If you are doing this with the users knowing cooperation, that might be a solution. If you control both code bases (the PHP and C#), then it's more likely, it would make more sense for the user to run the desktop app and for it to communicate with the PHP page to get the info it has.

C# + PHP in the same application?

What im trying to do is a little different, im wondering, if its possible to create sorts of an interface, so that if a particular function is called in php (stand alone), than the arguments will be forwarded to a method in C#, and vice versa.
Depends of course on what kind of data you want to exchange, if the applications are on the same server or on two different ones etc.
I did briding between PHP and C# in some of my web based projects. What I did: create an ASP.NET MVC project which exposes a RESTful API. The methods exposed by this API are then called from PHP via HTTP (using CURL). I used JSON as a data exchange format to pass data from PHP to C# and back again. This worked good as the two applications were on different servers.
I could also imagine some kind of socket server. E. g. a background process written in C# is listening on some port, and then you connect to it via PHP´s socket functions. I did something like this to connect PHP and Java. The Java app ran as a demon process on port XXXX and was a wrapper around Apache FOP. I used PHPs socket functions to pass XML and XSLT to the Java demon which then used Apache FOP to transform the data into a pdf and returned that via the socket connection back to PHP which in turn sent the PDF file to the client requesting the page.
There are probably some other approaches, but these were my experiences so far in connecting two different technologies together.
EDIT: as an aside: PHP on a windows webserver using IIS was really not that nice to work with. Sometimes strange errors occured or certain permission related errors that were not easy to resolve. YMMV though.

How to send data from local PC to Google-app-engine application?

I have to write client program in C# that have to take some data from DB and sent it to my Google application(Java). How can I do that? What is the best way to do that?
It'll be great if there be some code example in answers.
You can put your data in JSON format and send it with server request, but I`m not sure does JAVA support working with JSON.
You need to create a web service in your app engine app that would take post data and consume it.
Preferably Use a web service framework otherwise you will have to do a lot of xml parsin yourself, which is baaed. mmmkay
Now I dont know if ur using py or java, but do look for a web service framework in ur language. mmkay

C# & PHP: Simple example of PHP Web Service used by C#

Could anyone give me a small and simple example of how to do this? Or some good pointers on how to get started.
I would like to create a C# client that can send a file or some text or xml or whatever, to a web service or something similar written in PHP, where the PHP Web Service stores it in a file or a database or something like that. Just not sure how to get started.
I guess the first step would be to create the php web service. And then it perhaps would be quite easy to use it in C#, since I could probably pretty much use the "Add Web Reference" button in vs and then go from there?
You can take a look at this tutorial showing how to develop a web service using php. The .NET client will be pretty straightforward as you mentioned.
I'm not versed in the C# aspect of your question, which you intend to be the consumer. But if you don't mind using a library to expedite the process of getting the webservice up and running, you can set one up very quickly using Zend Framework. Check out the documentation for setting up a Zend_Rest_Server.
Just a thought... if the service only has to support simple operations like "upload a file", perhaps avoid WSDL all together? I assume PHP can handle raw requests - so you can use the oh-so-complex .NET client:
using (WebClient client = new WebClient())
{
client.UploadFile("http://some/upload.php", "foo.bar");
client.UploadString("http://some/upload.php", "some text");
}
etc. Likewise, you can often easily use POX / REST without the complexity of a formal web-service contract. The above code just does a simple HTTP request with the file-contents/string in the body.
you are right. all you need to do is to create a simple web service in PHP, which accepts the request/xml/file and then stores it in a database. then you can use the webservice using any technology, C# for sure.
in order to write a web service in PHP, I think it is better to choose your webservice type in the first step. it can be a REST web service, or SOAP, or XML-RPC. it depends on the level of complexity of your application.
if your application is as simple as just throwing a string to the webservice or a file URL, so then the webservice can store that string, or fetch the file from the URL and stores it in database, I recomment REST. because it is simpler. as simple as just writing a simple PHP script that uses it's HTTP parameters as input.
but incase you want it to be more secure or have more complex needs, It is easy to have SOAP services in PHP. if you wanted to work with SOAP, PHP has an extension (php-soap) which you can install and use the built-in functionality of PHP-SOAP. if you are using an older version of PHP that does not support the extension, or your application will be hosted where php-soap is not installed, there is pure PHP implementaion of SOAP protocol, named nusoap. it is open source and works very well.
http://sourceforge.net/projects/nusoap/
I have made work in PHP NuSOAP webservice and my C# mobile client fetching data from web services.Below is the link
http://khanmubeen.wordpress.com/2010/11/18/web-services-with-php-nusoap-c-mobile-client/
In case you like to know more from me welcome to inbox me at mubeen44us at gmail.com

Categories