I'm currently writing an http server in C# and I'm planning on allowing it to use PHP. How does PHP work? Like, the compiler or whatever it uses. I was thinking it takes php files in input and outputs the html or whatever file for the http server to give to the user's request. Is it possible to call on the php compiler or whatever with the file requested by the user? Please tell me if I'm thinking about this the wrong way.
Thanks
There are a couple ways to interact with PHP. The easiest way to get started is to implement CGI in your program.
Wikipedia has a nice example.
Basically, you execute PHP-CGI.exe, and send/receive data over standard in/out.
Related
I want to make a program in either C# or Java that can read all of the network data sent to another program I have open. I want to then save this in a log file. Can anyone give me some suggestions as to how I can achieve this? (I would prefer to use C#)
You can create an Http Proxy to capture the network traffic (assuming it's http), just as the popular tool Fiddler does. Take a look here: Any resource/codes on how fiddler works?
I've got a SSL connection working with my website alongside PHP sessions. I have created my own connection class to provide a single sign on, allowing my user to then interface with php script outputs from my website. I have a question though, currently I use my PHP scripts which query the database and formats the data into a HTML page, which my program then reads over the SSL connection. My program has to parse the data which may be slow for large data volumes. My question is:
without having to radically change my system architecture, is there a way to make passing the data between the server and the C# application more efficient. Currently I'm using string delimiter parsing to extract data in a way similar to command seperated values (CSR).
I've heard the word JSON passed around alot, but I think I might as well use XML instead.
SERVER: MySQL, PHP, APACHE
Thanks
Thomas
What you want to research is c# web applications and a SOA architecture. JSON or SOAP will be the transfer protocol on which your PHP will talk to your C#. What you will need to do if you decide to use soap is make a c# web service as an endpoint between your PHP and your database and the c# will talk to the DB and pass the data to the PHP. you may want to look into caching as well but that's only if you need scalablity. One thing that is nice about PHP 5 is that it has a built in method to talk to the soap protocal which just turns it into an array of values passed from your C# it makes it very easy to do. What your going to need to happen with your PHP is you will need to replace the SQL querys with SOAP connections. One more thing to consider is a WCF service because webservices have been "deprecated" in anything above .net 3.5. Hopefully it shouldn't be too painful
http://php.net/manual/en/class.soapclient.php
Scroll down a little on this page it has some good examples for your calls.
JSON is suppose to be a quicker protocol then SOAP I just do not have alot of experience with it myself.
Handling data in a PHP JSON Object
SOA the main concept apply to c# as well
http://www.javaworld.com/javaworld/jw-06-2005/jw-0613-soa.html
I am not 100% sure about c# and mysql connections I am sure there is stuff out there for it. I think the biggest problem you may have is hosting a C# service on an apache server.
Maybe check into using JAVA web services, I know it works well with apache and mysql and is used by alot of major websites.
I was wondering if it's possible to create an application in C# to streaming video to a php client. Someone out there have already try such thing or can indicate where to find resources to do that?
What do you mean by a PHP client?
Last time I checked, PHP was a PURE server side technology, and the "client" is a web browser that does not care about what the server uses but interprets the PHP output which are essentially strings in HTML and JavaScript.
So, what you want to achieve having a video decoded on the server? Send them as JPG images to the client?
You just take the reference of this link. You will get the idea to resolve your problem.
UDP Streaming transfer from C# application to PHP webpage
So I'm working on a project for my internship and have hit a bit of a brick wall. Unfortunately, the only people I know who are qualified to help me at the office are on vacation at the moment, and Google has been unfortunately unhelpful (or my search skills inadequate), so I thought I'd ask here.
The project is basically to make a server to mimic one that the company (which makes phone apps) already has. What I need to do is have one of their apps send a request to my server (I will have to modify the app to do this, but don't know how), and have my server reply with an XML response that the app already knows how to process. (The main purpose is so that we can see how the app responds when the real server sends it an error by simulating it on my server.)
Now, I already have a few sample HTTP requests and their associated XML responses handy, taken from simulations with the app and the real server. The app is written in C#, and currently sends HTTP web requests to the real server's online location, which responds to these HTTP web requests with XML. My server, however, will not have an online location, so the app will have to be modified to work with sockets on a local host.
My questions:
1) My boss said to create an XML file to associate certain requests with certain XML responses, but I have no idea what he means or how to do this. (He said it could also be done with a .ini file.) Does anyone know?
2) Once I have this XML file that can make these associations, how can I incorporate it into my server so that my server can check the request it received against its table of valid requests and figure out which response to send back?
3) How can one modify the app from using HTTP web requests and responses to using sockets?
If you have any questions/clarifications that you need in order to better answer this, please don't hesitate to ask me.
Thanks!
What you're describing is a web service. Unfortunately, his advice to change a setting in an .ini file make it sound like they have a proprietary system for doing this, rather than using a standard ASMX (which requires IIS) or WCF (which can either run in IIS or as a standalone service, which it sounds like is what you'd want) service.
Without more information about what they're using, I don't know that you'll be able to get much help here.
In response to question #3:
HTTP is a protocol that already runs on a specific socket (normally using port 80).
An internet socket is an endpoint that is used to transport data between processes. If you want to run your own protocol, you will need to create a new socket (with TCP or UDP) on a specific port.
This will however require you to create your own client and server in order to exchange data between them.
To get started, here is a very simple client-server example in C# using a custom socket.
Good luck!
Ask your boss if this client communicates with soap, if so then just go to MSDN and find tutorials on implementing an ASMX webservice, follow the tutorial through and you'll have a shell to start with.
First I'd like to say that it sounds like you have some unclear requirements that you should probably clarify with your boss. If you're not exactly sure what he means you should find out because nothing sucks more than having to support someone's creative interpretation of requirements.
1) It sounds like your boss just wants a way to easily change associations for testing without having to rebuild the app so he's asking you to store those associations in an xml/ini file that can easily be modified. In c# you can easily go between XML and DataSet objects so this should be trivial. I would create the data structure in a DataSet first and then use the GetXml method of the DataSet to output the xml format.
2) In .NET you can store objects in Cache and create a Cache Dependency that is a file association. Thus whenever the file is modified the Cache is purged. Whenever your program handles a request it pulls the object from Cache, if the object isn't in Cache then you have a condition block rebuild it from the xml/ini file on disk. I would have that condition block call out to a function that then loads the above mentioned xml format into a dataset that is then stored in the Cache with a Cache Dependency.
3) If you are trying to test an applications i/o, modifying it to use a different transport layer sounds like a bad idea. If the app currently works over HTTP to send requests then just route the HTTP request. I would suspect that the app probably has a configuration somewhere defining the path of the webservice it currently calls out to, once you know what that path is you can either change it, or if that's not possible setup a DNS rule on the server running the app to route it to the location of your application. On windows this is as simple as adding a line to the hosts file.
I'm wondering if theres already a combo let say jQuery - Some C# DLL to proive a secure both way communication between ASPX forms with jQuery and a control layer based on ashx files with C# classes...
[From comment below]
Well I see I have to be more specific. The are things like sniffers on simple network analysis tools even like Firebug that let you see the data transfered via POST or GET. The idea to secure a Server Client application is to ensure that data isn't corrupt and compromised, and to achive that you have to make imposible to an atacker to report false info so the best is to have improved some cryptographyc algorithms both on client and server to crypt decrypt encode decode data...
The only way you can ever make web communication secure between a client and a server is by using SSL.
Here is a Javascript AES engine.
However, you really should use SSL instead.