Perverting windows with PHP

It's been awhile since I've written. Summer is always a busy time with vacations and summer sports and dealing with four little ones at home. However school has started again and I'm officially "back to work".

Sara Golemon is one of the "Big Names" in PHP development, and one of my personal heroes for being a nice example of how women can succeed in open source and computers in general. Anyway, she's completely corrupted me. Now when I'm trying to write something and I can't get it to work, or want some kind of new functionality for PHP I keep thinking "I can make an extension for that..." Is this good or bad? I haven't a clue.

Now before I continue, just a qualifier. I like to work on windows - don't egg me. I use lots of the evil empire's products at work every day, and face it, some people do use Windows because they like the way it works. For me, I see windows as two entities...the geeks with their product, and the business sharks (that I don't really interact with). Also, the best way to get people interested in open source is to start introducing them to products on an OS they already know. Move them to firefox, thunderbird, and openoffice. Then swap out the backend for Ubuntu and they won't notice the difference in how "their" programs work. People hate change - remember? So make it gradual... Also it's never a good idea to bet all your eggs on one technology, whether it be linux, apple, unix, windows, commodore amiga... So I have several OS's running here at home and keep at least general knowledge on how to deal with all of them.

Back on topic. Writing desktop applications with PHP is considered to be idiotic by many people, but personally I think it's a lot of fun and can be useful. Using a scripting language for desktop apps means totally bypassing the whole compiler issue (we let PHP take care of "does this work on platform X"). Python has been in use for desktop apps for a long time, in many varieties... and though I could just go learn a new language, Python drives me a bit batty, with it's "some whitespace is semantic" stance (otherwise it's not too bad, I just personally don't like the syntax...totally subjective viewpoint...anyway).

I do some C# and could dive into some projects that way, compiling them to ride on mono or .net, but I really don't like compiling, even if it's to a format that can be passed around. The point is, I'm nuts enough to try to get PHP to cooperate with me. Also any idiot can learn PHP pretty easily (whether this is good or bad could be argued).

There are more solutions for desktop apps with PHP than people probably realize. I've been using php-gtk2 for quite a while, and actually learned C to help out on the project and am helping out with the windows end of things. There's also a qt4 solution in the works, and yes I've already volunteered to help with windows builds there...(yes, I am nuts). There's no Cocoa or wxWidgets wrappers...yet... (I can write an extension for that...)

Due to my "day job", I'm primarily concerned with the windows end of things, and having to install a toolkit layer to make your desktop show pretty windows can get really heavy. So why isn't there a Win32 GUI wrapper for PHP? Well, there is...kind of.

Winbinder plugs into the win32 API and allows windowing applications with PHP, however I have some real issues with the library.

  1. Started as PHP4 lib, just recently got a PHP5 port...and PHP5 dlls are never up to date
  2. Does not harness the power of PHP5 in any way, completely function oriented and the PHP end of the API is probably the most confusing, poorly designed I've seen.
  3. The developers have no idea of what help PHP5 can provide, have obviously never use PHP5 or understand how/what it's improved, and have no intention of moving to a nice OO API - so jumping on the project is out of the question (a lot of this probably has to do with backward compat... but since PHP4 has been end of lifed..what's the point?) There is an OO "layer" promised, but what I've seen so far is less than impressive
  4. The code is not threadsafe in any way, shape, or form - they use REAL GLOBALS...

So at the end of the day, I'm back to "I can write an extension for that." Prior art here included perl's wrapper for the win32 API, see I'm not the only weird one. So I am working on an extension currently called WinUi (really should be Win::Ui ...namespaces anyone??) ... it's still in progress, since the Win32 API has an enormous amount of junk I could add in, but the basics of window creation, moving, animating, and registering your own windows "classes" all work (and I've only been doing this about five days). - warning, that's a really large little movie (jing is pretty cool).

I'm loving the new features in PHP5, like the custom object support and intercepting setting and getting properties (you can do $window->size = 300 and use the right win32api call to change it ...all transparent from the PHP side of things) And although there's an issue with lack of documentation...I can always annoy Sara if I really hit a brick wall. (Thanks for putting up with n00bs)

Eventually I hope to have a WinUi, WinGdi, and WinSys (processes, threading, registry, et al) to put in pecl. There are some win32 only extensions in PECL, but win32std is the only one I've actually had use for, or even got working properly, and there's no agreement among them in naming convention, API design, or even functions vs. classes. So here I am, playing.

For now, give me a mail, ping if you want to play too and I'll stir myself to get the current code into source control or even throw up some (probably very rough) dll's to play with if you're crazy enough to help write tests/find bugs/grouch about the API design. And all you "My OS is better" zealots who will bitch about "Why are you bothering with this, we don't care about windows, and my toolkit/OS/extension is better than yours" - go jump off a cliff.

UPDATE: Started putting code up in SVN - give me a holler if you have patches, want to help code, whatnot, I'll throw up some test dlls shortly

Comments

Matthew Turland

Hear, hear. :) I'm another multi-OS person and I too think that Windows has seen too little support in the PHP realm. PHP users who use Windows have been treated like bastard red-headed stepchildren and I'm equally tired of the presence of that stance in the PHP community. I hope your WinUi project goes a long way and possibly even to contribute to it myself one of these days when I get around to picking up C again. Good luck!

2007-09-08 8:54 am

Brutos

Yeah! *jumps into the air and is happy now*

2007-09-08 1:22 pm

Ali

I agree with Matthew here. In fact, 2 of my friends turned to .net for the common "Not supported on Windows" line.
I would love to see your code put on version control. I have some experience in winapi and I am really advancing in PHP. I can have another 2 guys with testing I guess.
Good luck and let us know :)

2007-09-08 2:27 pm

Aaron

Structurally, winbinder is pretty sound it would be trivial to build a PHP5 OO interface to interact with the winbinder pecl extension.

If you are going to re-invent the wheel then I would suggest you create a modular interface which can be swapped with a QT4 or GTK or win32api backend.

2007-09-09 10:34 am

auroraeosrose

Aaron, perhaps you like the winbinder API but I wouldn't call it "sound" in any way shape or form. I can crash it on a regular basis (last I looked at the source code they're not handling globals per thread properly) and the API is not intuitive or flexible. If you want a "modular interface" to swap out the native backend with the same front end code, then talk someone into wrapping wxWidgets which already does this at the C level.

As far as the PHP5 OO stuff, I'm implementing it at the engine level, which allows for some neat tricks - for example $window->height = 300; will transparently call the correct WinAPI call to resize the window, and since it's done at the C level and not as a PHP wrapper around a function based extension...it's damn fast. You can't do things like that with any kind of acceptable speed using a PHP level wrapper (or even a C level wrapper around winbinder)

2007-09-09 4:35 pm

PHPDeveloper.org

Elizabeth Smith's Blog: Perverting windows with PHP...

...

2007-09-10 4:06 am

developercast.com » Elizabeth Smith’s Blog: Perverting windows with PHP

[...] a new post, Elizabeth Smith talks about “perverting Windows” to work with desktop PHP applications [...]

2007-09-10 6:52 am

BJ Upton

You might want to work on your page layout.

This page is unreadable in IE6, you know that niche browser?

The flowers cover sections of the text.

2007-09-13 6:06 am

bearvarine

Its always nice when you discover you can do more with a tool than what it was originally designed to do. That's called "pushing the envelope" and its generally a good thing, because it can lead to something even better, like "innovation". That said, it is worth asking yourself, "is this a useful way of solving an actual problem for someone?" Translation: did you just put together some kind of Rube Goldberg Mousetrap Contraption that can be done far more simply and easily with another tool? If so, then you must ask yourself: "Why am I so resistant to learning how to use other tools that make what I want to do easier?" Hey, it happens to me all the time, its human nature. If you are good at speaking Swahili and it served you well in the past, who wants to start over learning Englis from the ground up? So much lost productivity... Well, that how the programming game is played, I think.

2007-09-13 9:36 am

auroraeosrose

BJ: get a real browser, this is just a personal site not something I make money off of - but I'll add an IE is stupid stylesheet just for you to turn off all images

bearvarine: depends I think on why you program - to "solve an actual problem for someone" or merely to do the programming because you can - which has a lot to do with personality. For me, this solves an itch I have, windows UI's without compiling and with a scripting language that be run on windows with three files, and a decent API to use while doing it. Has less to do with "learning to use other tools" and more to do with "not paying for proprietary tools" - kind of an oxymoron on windows ;) Also, the focus on "productivity" drives me nuts... some people don't program to meet some productivity goal, we do it merely because we enjoy doing it!

2007-09-14 6:33 am

bearvarine

Productivity simply refers to how much you can do with a given unit of time and effort. I don't program in assembler any more, because it is not productive. And not much fun either. Same with C. But I could if either were required. Thank god they are not. Personally, I try to be as language and platform agnostic as I can, but I know others do take sides, and there are legitimate criteria for making such choices in specific cases.

Anyway, I'm not really criticizing you here. Perhaps my first post was meant to be more of a self-criticism. When it comes to choosing the best tool for a task, I have seen a number of approaches, each with their own balance sheet of plusses and minuses. In the past I have traditionally taken the "if you have a hammer in your hand, lots of things start looking like nails" approach. I happen to be a perl lover, and I have definitely overreached in the kinds of things I have applied it to. But I am really good at it, "productive" you might say, so it is sooo tempting to use it, even when it is basically a stupid choice.

I have seen other people over-analyze a problem and choose what they considered "the best/optimal solution" combination of arcane and obscure tools that only 1o people out of a million have ever seen. Don't you hate those people that see 5 keywords in a text file and then suggest that we need to get Lex and Yacc or Flex and Bison to parse this strange new language? That is just plain insane. Yet I have seen actual managers in actual corporations go along with such arrogant, self-serving, self-aggrandizing ideas. THAT is what makes ME crazy.

2007-09-14 1:18 pm

Weekend Links - Windows & PHP, Vista-Style CSS Toolbar, Facebook Applications, CSS/DOM File Inputs, Browser History | BluDice Blog :: PHP, MySQL, CSS, Javascript, MooTools, and Everything Else

[...] Perverting Windows With PHP Awesome article detailing how you can write Windows executables using PHP. I see this as a great idea. If you can use a web language to do functions on the desktop, do it! http://elizabethmariesmith.com/2007/09/08/perverting-windows-with-php/ [...]

2007-09-15 9:10 am

Brutos

Im too stupid to compile the source ;(.

2007-09-16 10:56 am

auroraeosrose

I have an MSVC project in svn (2005 version), with all the libraries and stuff you need, so it should simply be a matter of opening the project and telling it to compile/rebuild. However, I'm not sure if I have all the files in svn yet, my life is really nuts at the moment (I'll try to get a working demo up this weekend)

2007-09-18 4:37 pm

Brutos

I tried it today and it love this project, its (still) simple and cool. I tried php-gtk and that one i really hate, it doesnt look like and feel like windows and coding for it isnt fun.

I cant wait for updates in the SVN !

2007-10-14 9:57 am

auroraeosrose

Glad you like it - and it does work now, I've got the callback mechanisms in place which was the really hard part. Now it's just a matter of filling in functionality.

2007-10-14 1:27 pm

Post a Reply