PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 28: How to distribute your PHP - GTK applications - Method 1?
Written by kksou   
Thursday, 21 September 2006
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   
<?php
include "http://www.kksou.com/php-gtk2/remote/hello_world.phps";
hello_world();
  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
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.


User reviews   Average user ratings:    4.5   (from 6 users)
  1. helder mauricio g ferreira
    February 28, 2008 5:31am
    error

    I could not access the file in question
    I tried to make an example with a full-gtk php placed on the server
    Oservidor interpleta the file and the error disendo that there is a class windows
    See the error below
    This is the file that I have on my desktop


    It is placed on the file server



    And this is the result


    Fatal error : Class' GtkWindow 'not found in / var/www/php-gtk2/remote/mudacorfundo.php on line 2

  2. kksou
    February 28, 2008 6:31am

    Hi Helder,

    Sorry the article above was a bit "messed up" when I transfered it over from the previous version. Have just fixed it.

    Take a look at the article again. You can place the bulk of your codes in your server. But the program itself must be run from your local machine, where PHP-GTK2 is installed.

    Based on the error message, it seems that you're trying to run your code on the remote server, which does not have the php-gtk2 installed.

    If you still can't get it to work, could you please post your code in the forum. They did not appear above.

    Regards,
    /kksou

  3. Cláudio César Monteiro dos Santos Júnior
    August 21, 2008 10:14am

  4. Wilson Oliveira
    June 05, 2009 6:51am

  5. Enexis
    August 17, 2009 12:15am

  6. Daniel Perdana Suprapto
    October 15, 2009 6:44am
    Hebaat...

    Sangat menambah kemampuanku dalam hal security...

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved