Discussion Locked

Developing Desktop Applications in PHP for Beginners

0 helpful
12 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Developing Desktop Applications in PHP for Beginners.

Outline:

1. Introduction.
2. What is PHP-GTK?
3. Where to get?
4. How to test the Installation?
5. Steps for executing a sample code.
6. Some Interesting Websites on PHP-GTK.

Introduction:
We have been creating web-applications using PHP since it came into existence, Now we come to know that we can also develop Desktop or Stand alone Applications with PHP-GTK.Desktop Applications are one which does not need either Web Server like IIS,Apache,PWS etc. or web browsers for their execution. One of the reasons why Java is so popular is because it can be used to build applications, web pages, applets and beans that can run on several platforms including Windows, Linux and Solaris. Java runs a virtual machine called JVM, and code is compiled into an intermediate format known as Java byte code, which is platform independent. When that particular piece of code is executed within the JVM, the JVM optimizes the code for the particular platform on which it is running as it is being compiled.

Microsoft's latest technology, .NET follows the same principles. Code is compiled into Microsoft Intermediate Language (MSIL) and is then executed within the .NET framework as an application domain. Microsoft is hoping to standardize C# and MSIL so that .NET code can run cross platform.

So what has all of this got to do with PHP-GTK? Well, both Java and .NET can be used to build windowed applications and web pages. Thanks to PHP-GTK, we can now build cross platform windowed applications with PHP as well.

What is PHP-GTK?
GTK is an acronym for the GIMP Toolkit and GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paint shop. It's the graphics editor of choice for most Linux users.

GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:
1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.

2. GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you're thinking along the lines of MFC for C++ then you're making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API's from the developer. GDK does the same thing for GTK+.

Where to get?
We can download binary as well as source code version of PHP-GTK from http://gtk.php.net/download.php .Now the latest version is PHP-GTK2 .As a beginner, it would be a difficult process to download and install in this manner. Where we need to set up another php.ini file for PHP-GTK.Instead there is another way of installing it. We can get PHP-GTK2 in an executable form as we get WAMP.EXE (Windows Apache Mysql PHP).All we have to do is just download just download the files from http://www.gnope.org/download.php ,unzip them and double click on the icon GnopeSetup-1.5.1.exe . It will run through a step by step process where it will set up PHP-GTK automatically.

How to test the installation?
Once the installation is done we would eager to know about what is special in it? When we install PHP we would run phpinfo () from root directory .For this let us run a sample script which displays Hello world (as usual) .we can use Dreamweaver for editing the code. Another important point to be kept in mind is to save the file with extension .phpw it can be saved anywhere on your Disk space.

Here is the sample code,Put them within php tag as usual.

if (!class_exists('gtk')) {

die("Please load the php-gtk2 module in your php.ini\r\n");

}

$wnd = new GtkWindow();

$wnd->set_title('Hello world');

$wnd->connect_simple('destroy', array('gtk', 'main_quit'));

$lblHello = new GtkLabel("hello world");
$wnd->add($lblHello);

$wnd->show_all();

Gtk::main();

I have saved this sample file by name hello.phpw at c:\test\.
We should run this sample code from command line interface CLI nothing but Command Prompt.There may be a question rising in your mind asking, why we should run through
command prompt than by just by double clicking it as it is a stand alone application. It is possible, for that we need to have some PHP compiler which converts our PHP-GTK code to EXE file .Now let us try running it from console or Command Prompt.

Steps for Executing a sample code:
1. Start -> Run -> cmd (for xp sp2 and later version) or command (for windows 98).

2. Now you could see a black window which is Command Prompt. Key in the following commands as shown below.

z:>c:
c:> cd test
c:\test>php hello.phpw

Once we finish this line and hit the Enter key, we shall get the following as output.

Yes, this is what the expected output is. This shows the successful installation of
PHP-GTK2 .An output without a web-browser.

Some interesting Websites on PHP-GTK:
1. http://www.kksou.com/php-gtk2/
2. http://phpgtk.activeventure.com/gtk/gtk.gtkbox.html describes about all base classes).
3. http://gtk.php.net/download.php
4. http://www.gnope.org/download.php

Conclusion:
Please leave your comments/feedbacks on this article, So that I can present better in future.Thanks in Advance.
Cheers!!

12 replies

by tony hopkinson

Please tell me it's a joke. :(

PHP is a terrible language and it was designed for server side scripting, essentially outputting HTML.

And as for cross platform, that presumably just like java or .net relies on something platform specific residing on the machine.

So I can see abslolutely nothing worthwhile in this idea at all.

by tony hopkinson

What executes the PHP code ?

Or what compiles , one or the other?

Is PHP-GTK not PHP then ?

Tell me why this is better than. NET, or even java

How is state put in to play ?

What's the performance like.

What threading options has it got ?

I aren't some cookie cutter in serach of yet another panacea !

by ahamedjais

1.we can execute from command prompt.provided your file should be saved with an extension .phpw (I tried putting some screenshot of sample could'nt attch here)

2.There are many Php compilers available for free some of them are Priadoblender,roadsend etc

3.PHP-GTK is a PHP module that enables the use of GTK functions from inside PHP. This allows us to build user friendly graphical interfaces quickly and easily in PHP.

4.It is easier when compared to .Net and Java.

5.could u pls make this Question more clear?

6.Performance is very good .I dont know to compare with some other language,as i have worked only with php.

7.I need to analyse about Threading ,I shall try to reply ASAP.

by tony hopkinson

That explains a lot.

Yes you can get many compilers for PHP.
Same as you can get many JVMs versions or .Net Frameworks. There are differences between them, as soon as you start stretching the language which you'll have to do to a rich GUI app, you are going to bump in to them big style.

So called source cross platform portability is a bad joke in the industry.

Don't even start with what version of PHP

Most of them are not PHP compiler's but PHP interpreters, so every time you run the php it must be compiled first. A Compiler takes the source and produces an object file which it then links and you then execute.
Java and .Net use an intermediate format (java byte code, or .NET IL), which is then interpreted by the JVM or the Framework.

Threading support in PHP is slim to none.

As for state PHP was developed for web applications so they go over HTTP which is stateless. To get state you are down to using cookies and such. How do you pass data between scrips?

PHP is easier, well sort of, as soon as you get past needing something fairly basic it's going to be harder though.

You need to start using some more langauges and environments, the inherrent weaknesses in this approach will stand out a mile.

Even if you were right and this is an easy step to application building, the beginner will have a serious struggle to step up to a more powerful environment. They'll almost be starting again and they could be chock full of what could be very bad habits outside of PHP.

I could not recommend this approach to anyone.

by jaqui

PHP has but one interpreter, available from php.net

It does have a cli module as well as the gtk module.
I personally wouldn't pick php for a full on desktop app, for the primary reason of a lack of state, though, as a desktop app you can use a set of global variables to get around that issue.
It is better suited for website scripting or system shell scripting than desktop apps.
[ shell scripting, the cli module ]
But, bash is far better than php for shell scripting, and perl even more so.
maybe if you are condemned to the miserable scripting of batch files on windows, php is a viable alternative to that. [ since perl for windows is a commercial product and php is free ]

I can see php-gtk being used as the client tool for an intranet app, if there is no one who has a more robust language to work with available for such a project, and you don't feel like having an intranet only webserver to use php as a web script tool, letting the company's default browser handle the user interface as you coded it to present in Xhtml & css.

by fgm

The PHP-GTK community site at http://php-gtk.eu/ may be more accessible to beginners than the reference sites you mentioned.

At the other end of the spectrum, http://perisama.net provides alternate builds, including ones with thread safety activated.

by ahamedjais

hello gentle man , thank you very much for adding this info to my post and keeping it alive.

by mak1e

i guess that mr. tony hopkins need to do some more research about PHP, Google is your friend.

some good example:
- sugarCRM
- ezPublish
- MediaWiki
- Wordpress

the list goes on...

by atakan.fall

Yes Tony You are totally right as I suspect you are an Old school programmer and I respect your knowledge. PHP-GTK is not "windows" programming, also true. However I look at it as a simple and easy stage for beginners to step in GUI programming since the logic is the same.

It is light weigh concerning your Q? about performance, the php-win interpreter takes about 25 mb of ram and my elaborate interface another 2-3 while performing a MySQL request from table with 60 000 positions , takes less than a second, and CPU load on Win XP SP3 spikes to 02 % (that's what task manager showed) :) However, It is what it is. Probably the topic was called wrong name. Tthe product I invest my free time in looks like a desktop app, performs well, uses MySQL server draws windows and all that good stuff that makes the operators happy :) , tries to access some low level system functions and system events, not impossible but .. well :)

When used long time it kinda hangs out yes. Have to take great care to destroy things and kill connections, but hell, its a nice tool and it has it's place under the Sun imho.
All the best to you ad thanks for the passionate discussion ! ]:)

This discussion is closed to new replies.