028. How to distribute your PHP - GTK applications - Method 1?

Problem

Suppose you have developed a GTK-PHP2 applications, and you would like to deploy this over 100+ sites within your company (or maybe school campus).

The codes are updated very frequently. And each update requires you to propagate the changes throughout the 100+ sites.

What are your options?


Solution

There are many different options for deployment of php-gtk applications. Here we present one method.

Please take a look first at the sample code below - yes, 3 lines only! Run the code, and you should get the output as shown below.

I'll elaborate more in the Explanation section.


Sample Code

1   
2   
3   
4   
5   
<?php
include "http://www.kksou.com/php-gtk2/remote/hello_world.phps";
hello_world();
?>

Output

How to distribute your PHP - GTK applications - Method 1?

 

Explanation

As you might have guessed, this method puts the bulk of the codes at the server side, in this case: http://www.kksou.com/php-gtk2/remote/hello_world.phps.

The content of the file is as shown below:
<?php
function hello_world() {
    $window = new GtkWindow();
    $window->set_size_request(400, 100);
    $window->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse('#CCFF99'));
    $window->connect_simple('destroy', array('Gtk','main_quit'));
    $label = new GtkLabel('hello world from remote server!');
    $window->add($label);
    $window->show_all();
    Gtk::main();
}
?>

The sample code simply includes the function above and calls the function hello_world(). Note: Please compare this with the example: How to set the background color of GtkWindow?

As documented in the PHP manual, "if 'URL fopen wrappers' are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL instead of a local pathname." And this is exactly what we using here.

By storing the main codes on your server, you only need to maintain one single copy of your code. There is no need to update any of the 100+ sites because they will always get the most updated copy direct from your server with the include statement.

Of course, this method is based on the following assumptions:

  • All the 100+ sites are connected by LAN or broadband.
  • The users are ok with the initial slight delay when launching the application due to the time required to download the include files from the server. Note that this delay is only during startup. When all the include files are downloaded into memory, the performance will be exactly the same as the "local" version.
  • You have relative amount of trust with your users. (Please see notes below.)

Note

DO NOT use this method if security is your key concern.

  • This method does not "protect" your code at all. Just type the url: http://www.kksou.com/php-gtk2/remote/hello_world.phps into your browser, and you will see the entire content of the file displayed. "Protection" is not the main purpose of this method.
  • It is possible that your user download a copy of your script, change the content, and then points the include to the modified local version. So if you think there are such possibilities, you might want to encode some security checks in your script to make sure that the user is running with the server copy of the include files.
  • One way to make it more difficult for others to read your code and make changes to the file is to obfuscate the php scripts on your server. Let me stress here that obfuscation is by no means sucured. To a hacker, they can reverse-engineer an obfuscated files easily.

The key advantage of this method is ease of maintenance and updating of your php-gtk application over large number of sites.

Add comment


Security code
Refresh