Category Archives: Software Development

Posts about software development. Generally I use Java, PHP, and Python for development but occasionally I delve into other things as well.

Adventures with PHP Compilers

I am in a situation where I need to protect some intellectual property in a PHP script.  The recommended solution is to use a code obfuscator (or compiler) to encode the script.  Currently the landscape leaves much to be desired in this area as far as PHP is concerned.  The industry standard seems to be Zend Guard (http://www.zend.com/products/zend_guard) which is created by Zend – the guys who make PHP – but this has a couple of down sides:

  1. It costs $1000 US.
  2. The web server must be equipped with the Zend Optimizer extension in order to run encoded scripts. AFAIK this extension needs to be compiled statically into PHP.  This would drastically reduce the portability of my scripts. 

The biggest open-source compiler is bcompiler (http://php.net/bcompiler), a PECL extension.  Code that is compiled using this extension can be run with the assistance of the bcompiler extension.  Since bcompiler is a dynamic extension (i.e. it can be loaded at run time) it is theoretically much easier for users to install it (for my script).  Not a perfect solution, but I was willing to accept this hassle in order to ensure the protection of my intellectual property. 

In the past I have had nothing but bad experiences with PECL.  The extensions never install like they are supposed to.  If you make it past the compilation errors and actually get it installed, it is usually an ordeal to turn it on, and can be even more difficult to get it working properly.  These problems are usually related to incompatibilities with versions of gcc, automake, libtool, etc.., and a few hours (or sometimes days) reading through the PECL bugtracker can usually get these problems solved, but, … you get the point.

Unfortunately my experience with bcompiler was no better.   I tried installing it on my laptop running OS X 10.4 and PHP 4.3 (and also PHP 5), but couldn’t get past make.  It gave an undescriptive error "Make failed".  A little bit of googling revealed that bcompiler may be incompatible with GCC 4.x – a bug report suggested I downgrade to version 3.x.  Frankly, I don’t feel like installing an older version of GCC just to get bcompiler to install.

No problem, I don’t need it to run on my lap top.  I have a web host running red hat linux.  Surly it will compile on there.  In fact it did compile.  After about 45 minutes of tinkering with the php.ini file and the bcompiler.so file, I was even able to compile a simple php script into bytecode with the help of bencoder (http://bbs.giga.net.tw/bencoder.php) a script created by Shen Cheng-Da to harness the power of bcompiler.  The only problem is that the compiled code doesn’t work properly.  I can include the compiled script into another script, but cannot call any methods from it – and the script gives a Segmentation Fault on exit without any explanation.

I’ve looked far and wide for a solution to this one.  PECL bug tracker is full of reports of segmentation faults but the solutions don’t appear to transfer easily to this context.

Conclusion:  bcompiler is not ready for primetime yet.  Please someone correct me if I’m wrong on this point.

On to another commercial compiler: Source Guardian.  This is perhaps the most promising of the bunch.  It takes an approach similar to bcompiler in that scripts encoded with this product can be run on any server using a dynamic php extension.  The difference is that this is much more polished and feature rich, and the dynamic php extension is distributed as a binary, so the user doesn’t have to mess around with make and gcc.

I downloaded a 30 trial version of this software and tried to encode one of my scripts.  I am still in the process of trying to get this to work, … I’ll let you all know how it goes.

IFTPd

Ran across IFTPd (http://iftpd.sourceforge.net/)today and installed it on my westhost server.  This is great because I can run it on my virtual private server and create accounts for multiple users giving them access to exactly what they need access to.  It has a simple mechanism for defining groups and users, allowing you to create virtual file systems for the users and groups to work on. 

The default FTP daemon on my server was a little more difficult to work with, confining users to only their home ftp directory.  This is insufficient when there are multiple group projects under way.

IFTPd is also written entirely in Java and is distributed with all dependencies, so getting it running was a snap.

Still looking for a similar product for SSH, but for now, this works GREAT! 

 

Dataface 0.6 almost there

OK.. enough talk, already.  I have been using Dataface 0.6 for a couple of months now on development sites (e.g. Science.ca) and now it is time to put my nose to the grindstone and document it so that others can figure out the new features.  I have started a few tutorials but there is a lot of work to do as this version adds mounds of features over the previous one.  New (complete) features include:

  • Improved templating/customization support
  • Addition of an Application delegate class.
  • Fine-grained pluggable permissions framework
  • Modular, extendable actions framework (user can now define custom actions).
  • Integrated authentication support.
  • Multilingual support.
  • More widgets
  • New look and feel for improved usability.
  • more … to many little things to list here…
  • !! More customizable !! 

PHP WebDAV Library

I woke up at 3am Saturday Morning as a result of an epiphany.  I recalled that PEAR has a WebDAV library that will allow me to make any heirarchical structure accessible via webdav.  I downloaded the library and played around with it a bit and found it to work beautifully.  Using webdav, Mac OSX or MS Windows can connect to the script as if it were a network file system and open files directly in the Finder (in Mac OS X’s case). 

 So, I got to thinking…  Using WebDAV and Dataface, it would be possible to build a CMS with MySQL that is completely accessible via webDAV.  In other words, the content could be stored in a database, but editors could access it via webDAV to edit the content in their favorite programs like Word, Dreamweaver, etc…   I slapped away at the keyboard all morning, and finally stopped when I decided that I needed to first complete support for surrogate views in Dataface before I could complete this elegant CMS.  

 

This CMS is hot on my fingertips though, so it will be coming soon. 

SSH Tunnelling

SSH Tunnelling has been around forever, but I have finally started using it – and WOW!  SSH Tunnelling is useful when you need to edit content on another machine, but you don’t have direct network access to it.  It can be used when you are in a situation where you have to first SSH into one machine and then SSH from there into your destination machine.  Some examples later.

Dataface 0.6

Since the end of school I have been working feverishly to finish my next release of Dataface.  Version 0.6 will offer some nice internationalization features in addition to improved templating and action support.

One major deficiency , however, was recently pointed out by a Dataface user:  Dataface currently doesn’t support relationships to one-self.  This sort of relationship will be crucial for any future development of a CMS based on Dataface.  It will be a delicate ordeal adding this support as I will have to rewrite much of the relationship code – but I think I’m up to the challenge.  Thank God for the good ol’ SQL Parser.  With that little tool, anything is possible.

 

Internationalization and Multilingualization

I am up to my knees in the entrails of Dataface as I attempt to take it to the next level.  I am currently working on the 0.6 release and hope that it will be available for download in early May.  The big bit that I’m working on right now is Internationalization and Multi-lingualization. 

Internationalization:

I have added a LanguageTool class whose job it is to translate text.  Developers can provide language ini files with translations for multiple languages which the language tool uses for its translations.  Dataface provides a smarty {translate} tag that translates a section of text, so that internationalizing a template is just a matter of wrapping the text sections in {translate} tags and creating the language files.  Once one translation is done, the language file can be translated easily to produce additional translations.

Multilingualization:

 One of the more difficult problems to solve in Data driven applications is how to deal with mult-lingual content in the database.  Dataface will solve this problem by defining conventions for table names.  For example, if we have a ‘Profile’ table with fields "ProfileID", "Name", "Phone", and "Blurb", and we want the "Blurb" field to be multi-lingual,  then we create an additional table for each translation named "Profile_<language_code>" where <language code is the 2 digit code for the language (e.g. Profile_en would contain the english translation, and Profile_fr would contain the french translation).

Then Dataface would be able to load and save records transparently in the proper language according to the language that the user has selected.  Dataface will provide a wrapper db_query() function that can be used in place of any mysql_query() call that will automatically parse and convert the query to extract the proper language translation.  This will make it almost trivial to convert an existing PHP/MySQL application to a bilingual application without even having to change the application structure.  Just swap the mysql_query() calls for the dataface db_query() function.

In addition to this low-level conversion, Dataface will provide a "Translation Form" to translate records from one language to another.  It will be similar to the existing Edit Record Form, but will show one language translation and allow the user to edit another language translation and save the changes.  Good API support will be available so that forms can be created easily programmatically and placed anywhere in the application without having to change the existing application structure.

Anyways.. stay tuned 

SFU Article

Barry Shell wrote an article about me and Dataface for the FAS newsletter and it showed up on the SFU homepage (http://www.sfu.ca) as one of the stories on random rotation.  That was really cool.  It seems like everyone I know saw it because a lot of people have made comments.