Art AboutFAQWrite for usContact InfoRSS Feed
Search A/R/T:

What is PHP-GTK?

by Scott Mattocks
Click to rate:    
238 votes / avg. rating 17.45%

PHP-GTK is the Cinderella of the PHP world. Most people dismiss it as an impractical curiosity trying to fit in where it doesn't belong. It is a desktop application extension stuck in a web developer's language. After all, most PHP developers make their money building websites. To all of these “Wicked Step-Sisters” I say, don't be so quick to judge. Take a moment to look beneath the surface and glimpse at PHP-GTK's true potential.

At one point, PHP was strictly a web server module. It allowed a developer to create dynamic, database driven websites with relative ease. The syntax was easy to learn and it could be combined with inline HTML to create a powerful web application more greater ease than with Java or Perl. This combination of simplicity and power attracted a lot of attention. As the PHP community grew larger and stronger so did PHP itself.

Evolution of an Extension

At some point, during the development cycle, functions for interacting with the file system and operating system were added. These laid the foundations for a major step in the evolution of PHP. Breaking free of the web server, some brave developer decided to modify PHP to allow it to be run from the command line. This meant that instead of just showing data from a database, a PHP script could be used for anything a regular command line script could be used for, such as cron jobs, reformatting files (from CSV to XML for instance), or uploading data to an FTP server. What this meant for the PHP developers is that they themselves are now more powerful. They can write complicated utilities that normally would have been written as bash scripts with the easy and power of PHP.

When the stdin and stdout streams became available, simple command line executables could interact with the user, asking questions and gathering input. These two streams opened up the command line interface (CLI). PHP CLI had become a bonafide solution for developers that needed to create interactive command line utilities but didn't have the time or desire to learn a shell scripting language.

With interactive command line capabilities in place, the next logical step was to improve upon the simple text based user interface and create a graphical user interface (GUI). Enter PHP-GTK. PHP-GTK provided the tools needed to take CLI scripts to the next level.

PHP-GTK is the result of an evolutionary progression, not a Frankenstein monster created from spare parts.

Yeah, but what is it?

OK, so no we know why PHP-GTK exists, but the question “What the hell is it?” still hasn't really been answered. Strictly speaking PHP-GTK is a PHP wrapper around the Gtk+ library. The Gtk+ library is a C library that lets a developer create elements on the screen that can react to user interaction.

In many ways, Gtk+ is like HTML. Just as HTML tells a web browser where to place buttons, text, and other elements within the browser, Gtk+ tells the operating system where to place buttons, text, and other elements within the user's computer screen. As a Gtk+ wrapper, PHP-GTK lets you create and control these elements using PHP code instead of the native C code. PHP-GTK takes something that would appear foreign to most PHP developers and make it more comfortable.

What would I use it for?

PHP-GTK provides a GUI for PHP scripts that run on the user's desktop. It allows for multiple points of interaction by allowing the developer to create 'on-screen' elements that can react to the user's actions. The need for a GUI should be pretty obvious for some applications. Picture trying to create a spreadsheet from the command line or even as a typical web application using HTML.

With other applications the need may be more subtle. Many developers have used PEAR to install and upgrade PHP packages. But not all these developers are aware that PEAR has a PHP-GTK frontend for managing packages (try running: pear -G). While the PEAR command line utility is very useful, it requires the user to know the commands they want to commit and the packages they want to use. The PHP-GTK frontend presents the commands and packages in such a way that it is not necessary for the user to know all the ins and outs of using PEAR or all of the packages they need.

Aside from providing a different presentation, PHP-GTK has another advantage over “regular” PHP. It is run client side. Any time that a problem calls for code to be executed on the user's computer, PHP-GTK can be used. For example, managing an MP3 library would be difficult via a web based solution. With PHP-GTK the MP3s on the user's system can be quickly organized and inspected without having to transfer files to a remote server.

Even though PHP-GTK runs client side, that doesn't mean that it cannot communicate with a remote server. In fact, moving data processing away from the server using a PHP-GTK application can be a good way to save on server side resources. Think of reporting systems for a moment. Often times creating a report consists of collecting a large amount of data from a database, crunching some numbers for a while and formatting the output as a graph, table or maybe even a spreadsheet. The number crunching can be very resource intensive. Instead of doing this processing on a web server, which is designed to better handle remote customer requests, it can be done client side where resources are more plentiful. Displaying the results in PHP-GTK is no more difficult, and in most cases easier, than it is with HTML.

Another advantage of PHP-GTK is that the user does not have to initiate all actions. Web based solutions are request driven. This means that the user makes a request and the server responds. PHP-GTK applications on the other hand are event driven. This means that the application can react to more than just user requests. The application can process or transmit data in the background and inform the user when it is done.

Moving Forward

The latest version, PHP-GTK 2, combines the powerful object model of PHP 5 with the improved UI of Gtk+2.0. Currently, all development and documentation resources are devoted to making the first alpha release of PHP-GTK 2 happen as quickly as possible. Even though an official release has not yet been made, PHP-GTK 2 is already the standard for new PHP-GTK applications.

So now you know the “why” and the “what” of PHP-GTK. In the next issue we will begin to tackle the “how”. We'll start slowly with some simple windows and a button or two and eventually work our way up to a full blown application. In the mean time, here is a list of resources to get you started with PHP-GTK:

Scott Mattocks is a LAMP Developer for OnForce.com. He is also the author of “Pro PHP-GTK” (Apress 2006). Scott has been working with PHP-GTK several years. Not only has Scott been working with PHP and PHP-GTK, but he has also been contributing back to the community in many ways. Scott spent many hours to help improve the first set of documentation for PHP-GTK and is listed as one of the authors for the PHP-GTK 2 documentation. He has also contributed several PHP-GTK classes to PEAR and has added code to more traditional PEAR packages such as PHPUnit and Console_Getargs.

 Tags:  ,
 Add tag(s) (comma separated):
[Tags beta] — [Add New][Help]  

Tags Help

Tags are keywords associated with a web page that help classifying information. You can find a good explanation here.

To add one or more tags to this page, simply enter them below (separate them with a comma) and hit enter or click on the "Go" button.

New Comment
This form allows you to type in a new comment. Keep in mind the following:
  • The system accepts input in plain text format. Newlines will be converted to the HTML equivalent, and the system will try to catch most URLs and make them clickable.
  • Your e-mail address will never be displayed. We will use it only to notify you when new comments are posted to this page.
  • As a rule, we do not delete comments unless they are offensive, racist, spam or otherwise inappropriate.
  • Bold fields are required
Your Name:
Your e-mail:
Type this number:
Subject:
Comment:
Comments   New Comment
Nice article (#67)
By Roberto Bechtlufft on 2006-05-23 14:33:30

I'm very curious about PHP-GTK. At first I thought it was a kind of Frankenstein. But I got interested in GTK, and figured that it would be easier to learn PHP-GTK than to learn, say, Python and PyGTK. I'm very interested in this article. I hope next part will be even better, as I have many doubts regarding PHP-GTK.

[Reply to this]

Re: Nice article (#68)
By Scott Mattocks on 2006-05-23 22:21:31

Hi Roberto, Thanks for your comments. I'd be interested to know what doubts you have or your thoughts regarding PHP-GTK at this point. Maybe I can address them in the next article, which will begin to get into the actual coding of a simple PHP-GTK application. Thanks, Scott Mattocks

[Reply to this]

Re: Re: Nice article (#312)
By Kevin Huynh on 2006-09-06 01:26:48

Hi Scott,

PHP-GTK is client-side application. Is there a mechanism to protect a source code?

Thanks

[Reply to this]

Re: Re: Re: Nice article (#317)
By Sean Bernard on 2006-09-08 13:35:10

Hi Kevin,

I am aware of a commercial offering by Zend ie: Zend Guard - that is capable of code obfuscation, encoding and license management. It is really efficient but comes at a hefty price of $995 per year of subscription.

Regards

[Reply to this]

Re: Re: Re: Nice article (#494)
By Ahmed on 2007-03-16 06:56:50

Roadsend Compiler produces binary files for Windows & Linux, and it supports PHP-GTK. Give it a try, I really like it and it's free.

[Reply to this]

Re: What is PHP-GTK? (#584)
By haidar on 2007-08-22 11:06:54
Re: Re: What is PHP-GTK? (#586)
By JMWeb on 2007-08-29 00:27:11

Can PHP-GTK be used to create a desktop application as C# could?

Is the installation of Apache required?


Thanks for the article!

[Reply to this]

Re: Re: Re: What is PHP-GTK? (#621)
By Frdric G. Marand on 2007-12-31 18:13:22

Yes, it can it used to create a desktop application.

No, it doesn't require Apache or any web server, since this is GTK-based, not web-based.

No, it is not "as C# could", because it does not depend on .NET/Mono.

Check the community site at http://php-gtk.eu for various examples and tutorials (it was created a bit after this article so could not be included).

[Reply to this]

Re: What is PHP-GTK? (#591)
By Palanisamy on 2007-09-04 01:50:56

Is it possible to write .exe program in PHP and Will it beat c#....

[Reply to this]

Re: What is PHP-GTK? (#631)
By Michal on 2008-04-10 10:55:58

JMWeb,
"Can PHP-GTK be used to create a desktop application as C# could? " - no, can't....
<a href=" http://www.historia-powszechna.yoyo.pl">daty historyczne</a>

[Reply to this]

Re: Re: What is PHP-GTK? (#632)
By daty historyczne on 2008-04-10 10:58:29
Re: Re: Re: What is PHP-GTK? (#638)
By s33ds on 2008-05-06 07:44:18

Erh daty, what??

[Reply to this]

Index