8 comments | Posted: 5 June 06 in Books, by Nathan Smith

Pro PHP-GTK Did you know that PHP can be used to build desktop applications? Yeah, me neither. No, I don’t mean Ajax stuff that simulates the responsiveness of a desktop application. We’re talking double-click my icon, launch the program, self-contained type stuff here. I just finished reading Pro PHP-GTK by Scott Mattocks, which explains how to use the PHP-GTK extension to build powerful desktop applications. The implications for this are pretty big, because it means you can have data entry done from a controlled desktop environment, and also output the info on a website. This adds a layer of security by not having input fields on the Internet, yet allows for the benefits of displaying data online.

The book begins by explaining some of this history around PHP-GTK. By the way, PHP is a recursive acronym which stands for PHP Hypertext Preprocessor. Originally it used to stand for Personal Home Page. GTK stands for GIMP Took Kit. GIMP in turn stands for GNU Image Manipulation Program. GNU is a recursive acronym which stands for GNU’s Not UNIX. UNIX stemmed from UNICS, short for Uniplexed Information and Computing System. Thoroughly confused yet? Yeah, me too. All you really need to know is that GTK is a platform independent extension which allows for building of consistent user interfaces, and that the PHP-GTK extension allows it to interface with PHP.

Scott also walks you through the initial setup, then explains how to use the SOAP extension, as well as PEAR and PECL packages. He then covers the concept of widgets, which are basically aspects of a program that can be interacted with. Everything from buttons, scrollbars and text input areas fall into this category. Next up are events and signals, which happen within the application, and can let it know when something significant has occured.

There are several chapters on window styling, using the layout rendering library called Pango to handle the presentation. I suppose you could think of it like CSS for a GTK desktop application, though it contains far more logic and is lighter on stylistic aspects. It involves things like frames, boxes, tables, fixed containers, and notebooks which are basically tabbed areas of a program. He also explains window dependency. For instance, when a loading screen appears until a program is fully launched, or how all sub-windows close during shut down.

There are also a slew of chapters on controlling data entry, covering things typical in HTML, which are also applicable to the desktop. These include labels, entry fields, combo boxes, sliding scales / spinners, and traditional buttons. You can also build quite a bit of flexibility into the text handling, such as adding bold or italics, changing the font face or text size. Additionally, he explains how to make collapsible data trees and nested lists, and covers how to make custom scrollable areas. You can even make the application respond to drag and dropping of other files and formats directly into the graphical user interface.

The last chapter covers program compiling and distribution, so that users of your application won’t necessarily need to have PHP installed to use your programs. This helps make the whole process as seamless as possible. I also really like that from start to finish, he shows you how to build a real inventory tracking system, which could be used in real life. This whole book is cohesive, well thought-out, and quite comprehensive in its approach to covering PHP-GTK. I would highly recommend it to those who are already experienced with PHP, and want to become adept desktop programmers by using familiar tools.

Discuss This Topic

  1. 1 Nathan Logan

    Great review, per usual. I had no idea you could do this sort of thing w/ PHP. Next thing you know, somebody will invent a way to interact with databases with PHP!!

  2. 2 Yannick

    Just like Nathan L. I had no idea that PHP could be used to do that sort of thing. Sounds pretty cool. I wonder how it stacks up against Java and the like on the desktop?

  3. 3 Robert

    Yannick: I have always felt the Java compiler was a bit slow, maybe that is just me.

    This definately makes PHP much more of a valuable language in my book.

    Nathan: Thanks for giving me the heads up a bit ago about this. Definately something to look more into.

  4. 4 Robert

    Oh btw, Nathan does this book cover PHP-GTK 2?

  5. 5 Nathan Smith

    Robert: Yep, it does. The whole book revolves around PHP-GTK 2, which from what I gather is far more stable and developer friendly than previous versions.

  6. 6 Scott Mattocks

    Hi Nathan,

    Thanks for the great review. If we ever meet, I will certainly buy you a beer. I am glad that you liked the book. If there is anything left unanswered please don’t hesitate to ask me.

    Yannick: I have always found Java Swing to be too cumbersome. Just to make an empty window appear on screen you need to write 14 lines. With PHP-GTK it only takes 4. As far as functionality goes, I think the two are about equal. I can’t think of one thing that Java Swing can do that PHP-GTK can’t or vice versa. The only real advantage Java Swing may have is the availability of the JRE. It is on must user’s computers already and if it isn’t, it is pretty easy for a user to download and install it.

    Thanks again,
    Scott Mattocks

  7. 7 ketsugi

    C’mon, guys, this is the second book that Godbit’s reviewed that I really want to buy after reading the review. But I’m in a financial tight spot (just graduated, trying to get a job) and I’m not sure throwing out US$22.50 for the PDF versions would really be good stewardship at this point of time.

    Stop reviewing such useful books so I don’t have to keep feeling so poor! ;(

    This book looks like something I would really really like to have the chance to read, though. :/

  8. 8 JW

    Well, in fact PHP-GTK isn’t all that great. It’s quite slow compared to languages designed specially for desktop applications. PHP is made for web applications, and is best at that. Developing a desktop application with PHP and its GTK bindings can be a complex, painful job. I’d recommend to use a language made for whatever you’re doing: PHP is great online, but offline you should use something else.
    PHP-GTK is just a fun aside, something you can explore and try out, and then decide you probably won’t ever use it.


Comments closed after 2 weeks.