PHP Classes

Using PHP-GTK to serve Web Applications to HTML 5 Browsers

Recommend this page to a friend!
  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog Using PHP-GTK to serv...   Post a comment Post a comment   See comments See comments (5)   Trackbacks (0)  

Author:

Viewers: 253

Last month viewers: 66

Categories: PHP Tutorials, News

Yes, you read it right, GTK+, the Gnome Toolkit library, normally used to create desktop applications, can now be used to serve the same applications via the Web to a browser that supports HTML 5 canvas objects.

PHP-GTK is a PHP extension that uses the GTK+ library to build PHP desktop applications. So it can eventually benefit for this GTK library enhancements to build PHP-GTK based applications that can be served over the Web to HTML 5 browsers.

Read this article to learn more about GTK+ 3 HTML 5 canvas backend and how it could be used to run remote PHP-GTK applications that can be accessed over the Web.




Loaded Article

Contents

What is GTK+?

What is PHP-GTK?

GTK+ 3 broadway HTML 5 canvas backend

PHP-GTK applications served over the Web

Conclusion

What is GTK+?

GTK+ is a library of components to build user interfaces usually meant to run on desktop computer environments.

Its main goal was initially to help creating the user interface for GIMP, a popular Open Source image editing program very similar to Adobe Photoshop. Over time GTK+ became more popular by being adopted as the facto user interface library for applications running under Linux distributions based on the Gnome desktop environment.

GTK works on top of the Glib object system library. It creates objects which basically provide a way to render graphics in a platform independent manner. This means that the user interfaces created using GTK+ can work in multiple platforms like Linux, Windows Mac OS, etc..

What is PHP-GTK?

PHP-GTKPHP-GTK is an extension for PHP created in 2001 by Andrei Zmievski that makes it possible to use PHP to run applications with user interfaces displayed by GTK+.

Over time PHP-GTK got many contributors that helped making it work with GTK+ 2, as well making it work with PHP 5 under Linux, Windows, Mac OS, etc..

GTK+ 3 broadway HTML 5 canvas backend

GTK+ version 3 was released officially this year 2011. Despite the worked started earlier, version 3.2 that was released last September introduces officiallly two new backends for directing the output of GTK+ graphics: wayland and broadway.

The wayland backend provides an alternative way to render graphics by providing direct communication with the underlying graphics hardware. This is a faster way to render graphics than the traditional method used in Linux which relies on the X windows system. Read below for more information on the X Windows system.

The broadway backend can make the application graphics render in a Web browser that supports HTML 5 canvas elements.

The application runs on the Web server side and starts listening to HTTP requests on a given TCP socket port. A Web browser that accesses to that Web server receives a page with an HTML 5 canvas object.

To run a GTK+ 3 application and serve it over the Web is very easy. You just need to set the environment variable GDK_BACKEND to broadway before running the application. In a Linux shell it could be as easy as entering a command line this:


GDK_BACKEND=broadway gimp

Here is a demo video showing GIMP running inside Firefox by accessing the Web server started by the broadway backend:

Play Video

PHP-GTK applications served over the Web

Running PHP-GTK applications and serving them over the Web is indeed a very interesting new alternative to run PHP applications. GTK+ user interface elements are very rich and powerful. There are free visual tools to build GTK+ user interfaces that can be used to quickly build PHP-GTK applications that have rich user interfaces.

Other than that, being able to run a remote GUI based application over the Web opens also interesting possibilities. Actually providing a user interface for an application running on a remote computer is not exactly a new concept.

The X Windows system, or just X, is a protocol that allows precisely that since 1984 when it was created at the MIT. It was adopted by a great part of the UNIX based systems, like for instance Linux, as the de facto standard way to display application user interfaces.

It allows running an application in one computer and see its user interface windows on another computer. I remember using many X based applications running on expensive UNIX workstations when I was in college in the late 80s and early 90s. It was great because I could use cheaper machine to see the user interface of an application running on an expensive workstation to which I could connect on a local network.

X Windows is a more sophisticated protocol than for instance VNC. VNC keeps sending over the network whole graphic dumps of parts of the screen that changed. That is why it is so slow.

On the other hand, X Windows just sends small packets with parameters of the graphical commands that the display side needs to execute to render the application graphics. Those commands are simpler and require much less data transfer, like "draw a line from this point to that point" or "draw this text in this position using this font", etc..

The concept of X is so sophisticated that it was used by a company named Citrix to workaround the expensive Microsoft Windows NT workstation licenses. What Citrix did is to use a variant of X to create virtual graphic board drivers for Windows NT that made it possible to run applications on a Windows NT server and display their user interfaces in cheaper computers that did not need to run a copy of the Windows NT workstation edition.

X Windows is used as the default way to display application user interfaces on Linux, despite the user is on the same machine as the application that it is running. The X Windows server program is running in the background and the applications communicate with it to send commands to render the user interface windows and graphics.

As you may realize by now, X Windows can also be used to display user interfaces for remote applications somewhat like the proposal of GTK+ broadway backend. The difference is that X Windows is a totally different protocol than HTTP. Many firewalls, used for instance in corporate networks, let HTTP traffic pass, but they block X protocol traffic. So this is a clear advantage of the the broadway approach.

However, there are a few stumbling blocks that make it not yet possible to use PHP-GTK with broadway. One of the problems is that the current version of PHP-GTK only supports GTK+ version 2.

It may not be hard to make it work with GTK+ 3 too but the fact is that currently there is not much development going on in the PHP-GTK project. A group of motivated developers would need to get back to the project and update it to make it run with GTK+ version 3.

It is not hard to make that happen but somebody needs to do it. If you are interested and you have enough knowledge of the C language, you may want to join the PHP-GTK project and work on it.

Another challenge is to determine whether using PHP-GTK applications over the Web is a technically advantageous solution, when compared to traditional AJAX based PHP+JavaScript Web applications.

The matter is that once an application is running on the server side, the resources that it consumes will be taken mostly of the server. When I say resources, I mean mostly RAM. A typical HTTP request handled by PHP is short lived. It usually takes between 10MB and 20MB of RAM. So you can run as many PHP requests in parallel as the available RAM on the server permits.

A desktop application, like for instance those based on GTK+, does not exit until the user quits. So the amount of RAM that it will consume over time may become significant depending on what it does. The same Web server may not be able to run as many PHP-GTK based application instances as a traditional PHP Web application can handle simultaneous user accesses.

Maybe RAM usage is not your problem, especially if you only want to serve PHP-GTK based applications to a limited number of users, like for instance those in corporate networks. In that case serving PHP-GTK based Web applications can be a very interesting solution.

Conclusion

As mentioned above, running PHP-GTK applications to be served over the Web is not yet possible but it may not take much time to happen if this possibility raises enough interest in the PHP community.

Despite it is a very interesting new way to develop rich user interface PHP Web applications, there are circumstances explained above that make it less than ideal, when compared to traditional PHP applications based on HTML, CSS, JavaScript and AJAX requests.

Nevertheless this is a new space that you may want to keep an eye on to follow the eventual upcoming developments that can make this a more viable solution to build rich user interfaces for PHP applications.




You need to be a registered user or login to post a comment

1,616,107 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:



Comments:

2. That's wonderful - Pablo Santiago Sánchez (2012-09-28 12:33)
Great news... - 1 reply
Read the whole comment and replies

4. Litle say - Cici Wirachmat (2011-10-31 19:03)
About php and html5... - 0 replies
Read the whole comment and replies

3. Exciting - Corey Avis (2011-10-29 19:26)
Exciting stuff.... - 0 replies
Read the whole comment and replies

1. PHP_GTK - shijin (2011-10-28 06:46)
Good Post... Waiting for it to happen...... - 0 replies
Read the whole comment and replies



  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog Using PHP-GTK to serv...   Post a comment Post a comment   See comments See comments (5)   Trackbacks (0)