tags:

views:

231

answers:

8

Suppose I have a GUI-only application that runs on Windows and I'd like to create a web interface for it using PHP. Is it even possible? I know I can use functions like system() or exec() to launch programs, but can I have more control over a running GUI app? Primarily, I would like to be able to send it keystrokes, so I can use it to process a file, save the output, and exit.

Please point me in the right direction.

+1  A: 

I don't think it's possible to actually send mouse clicks or keystrokes to a desktop app via a PHP web app (if it IS possible, I doubt it's easy - or pretty). What might work is to take the functionality that the PHP app needs and move it to a separate library or service that the PHP app can call using a set of methods you expose to it.

FrustratedWithFormsDesigner
Could I do this if I used PHP from the command line? I don't think it should be that difficult to later call command-line PHP from a Web app.
MiseryIndex
In that case, your back-end service/library (that interacts with/passes messages to the desktop app on the machine that hosts the web app) would be written in PHP, and it would be called by a web application that also happens to be written in PHP. I don't see a problem with having the middle piece written in PHP, other than it's not my personal choice, but hey, different strokes for different folks! ;)
FrustratedWithFormsDesigner
+3  A: 

Does it have to be PHP? You can distribute your GUI application on the web using VNC's Java applet (free), Windows Terminal Services, Citrix and the like (not free). I can not think of a way to make this possible in PHP, not with it acutally "clicking" the GUI.

Pekka
By using these tools wouldn't I essentially give up control of my computer? What would happen if two people wanted to use my app at the same time?
MiseryIndex
There is a lot of applications and solutions out there, with more and less limitations. It really depends on your needs and budget what is the right one for you.
Pekka
+1  A: 

The most important thing you need to remember here is the old programming adage that programming languages are analogous to tools. You wouldn't try to remove a flat tire with a hammer, nor would you drive nails with a tire iron. The point: Use the right tool for the job. Using php to do what you plan on doing is like trying to drive a nail with a screwdriver. Find a good quality hammer.

Austin Kelley Way
Can you recommend an alternative hammer?
MiseryIndex
Java and Python have a lot of GUI options.
Austin Kelley Way
+2  A: 

You might want to look into php-gtk

wnoveno
I would if I wanted to write a GUI app in PHP. Could php-gtk actually help me do what I described?
MiseryIndex
No, it won't. PHP-GTK is used for building GTK apps using PHP.
cdmckay
+1  A: 

You can definitely do it, but it would take a bit of hackery. One way to do it would be to write a Windows command-line app that would send button clicks and such to the Windows GUI app. You then call this command-line app using PHP and the exec and system calls.

For example, if you were passing it say, Firefox, you would have a firefox-wrapper app that could be called like this:

firefox-wrapper open-url http://stackoverflow.com
firefox-wrapper press-back
...
cdmckay
Accepting as this is a path I will investigate.
MiseryIndex
+2  A: 

Can't say I've tried this myself, but you should have a look at PHP's Windows-only extensions, specifically, the COM extension (http://www.php.net/manual/en/refs.utilspec.windows.php).

From the intro in the documentation:

COM is one of the main ways to glue applications and components together on the Windows platform; using COM you can launch Microsoft Word, fill in a document template and save the result as a Word document and send it to a visitor of your web site.

You'll be limited to running scripts on your own box, but that sounds like it's what you'd need. The COM/OLE stuff can be a pretty deep rabbit hole, so good luck!

andymism
+1  A: 

Sounds very possible... Let the GUI application start up a local server, say at 127.0.0.1:[anyportnumber] Then whenever you do something via the web, let the PHP application send commands to your application by sending data to the GUI app that sits there listening to whatever commands it needs to react on.

Photodeus
+1  A: 

If you need to see the GUI running in your web application, the VNC viewer applet is the way to go.

If you are looking to provide a web form and manipulate your GUI behind the scenes, check out Windows Automation Tools on your favorite search engine. They have powerful scripting languages that will allow you to create complex (if needed) routines. You can invoke many of them from a command line and pass a script to execute. If you were doing this with PHP, you could even generate the script as a temp file and pass that off to the macro processor.

You might be able to get what you need from Windows Script Host (WSH), which is like batch file scripting, but with more features.

jheddings