Subentry of
PHP-GTK
Sun9Dec2007
I think a lot of people forget about some of the more useful features of their operating system when they start to write PHP-GTK programs: shared libraries.
In PHP, there is a config option called include_dir where you can tell PHP to look for files passed to include() and require() - and those functions when told to load files from a relative path and failing to find them in the local file tree... checks the include_dir.
On every system I have setup, this has defaulted to /usr/lib/php or /usr/local/lib/php which you might recognize as the folder which contains the folder which contains your PHP extensions. Those are the defaults even if include_dir is not set in PHP.INI!
Bob, all I heard was 'Blah blah blah...'
Take for example this code in a file called message.php:
require('libbob/notify-send.so.php');
Now lets assume that I was in the same directory when executing this file: php message.php. Now lets assume there is no libbob folder in the directory message.php is in. We just called a file that does not exist.
Now lets assume message.php was in my /usr/bin. Now when we run message.php the current working directory will be anywhere. It could have been /home/bob/notporn and I am pretty sure there is no libbob folder in there.
Because libbob was installed into the PHP include directory, the program message.php was able to load it without having a direct file reference, and without having to copy paste all the functions in notify-send.so.php into my program.
What did this gain us?
First. We just used a shared library, meaning multiple programs can find and use it without trying very hard.
Second. The shared library can be upgraded and bug fixed, fixing every single program that uses it without editing every single program.
Third. The size of your program distribution is smaller as you have not copied pasted code that could be in a system-wide location.
Why do you bring this up?
I bring this up because it is a bad habit of most developers using PHP-GTK to copy and paste other peoples classes into their programs. It is even a badder¹ habit to build classes for other people to reuse, and expect them to copy paste into their programs. If your class that generic, build it into a shared library! People can load it and then extend it to fit their needs on the fly.
Surely you have installed a program that had dependencies on another library before? This is the exact same thing.
Alright, but what is with .so.php?
Because, in Linux compiled shared libraries are .so files. PHP ones which are not compiled naturally should be .so.php
Also Because, those are the standards I set here, in KateOS being the first Linux distribution to take PHP-GTK seriously.
Oh, Okay.
I hope this at least made you interested. I will be following this up later with more documents such as "how do I build a shared library in PHP" and "how do I/others install my shared library"
I also plan to follow this up with the release of my own shared library, libbob-notify, allowing you to send notification pop ups using the notification-daemon from PHP and PHP-GTK.
¹ Yes, I know.