brettbrewer.com

Programming + Design

Home
Using the PHP DBG extension with Ioncube Loader PDF Print E-mail
Written by Brett Brewer   
Friday, 08 August 2008

If you just want to know how to load the DBG module with IONCUBE loader, skip to the bottom of this post. 

I hate encoded PHP files. I mean I REEEEEEAAAAALY hate them. Not only does it make it infinitely harder to modify an application that relies on obfuscated PHP files, but it also tends to make it impossible to debug the non-encoded parts of your site, so you end up having to do ridiculous things like diabling all your encoded scripts so you can run a debugger on your own files. What a tragedy for PHP programmers everywhere who have to deal with this BS! Every time I do a project that requires me to work around encoded PHP files, it literally adds hours upon hours to the development time...so much so that I could often have rewritten the encoded funtionality myself from scratch faster than I can code around it (I will actually probably start releasing my own free drop-in replacements for some very popular x-cart mods soon if I can't get the authors to release the source).  My advice as a PHP developer is, steer clear of encoded files whenever possible. If you must use them, put pressure on the developers to release unencoded versions, possibly for an additional fee, or ask them to at least document all the internal functions so you know what the heck is happening inside scripts that your own scripts will need to coexist and sometimes interact with.

Unfortunately, I spend the majority of my time these days hacking X-Cart source code and the majority of commercial X-Cart mods are encoded in some way.  So for instance, even if you only have one encoded file in your entire x-cart store that requires the Ioncube loader, you can't debug ANYTHING, not even your own files..that is, unless you know a couple of tricks.

First, you must use the php.ini method of loading the ioncube loader so that you can make sure it loads before any other extensions. If you're loading your ioncube extension dynamically by including it in the root directory of your site, this will not work. You must also call the DBG extension as a "zend_extension" instead of a normal extension, and do it directy after loading the Ioncube loader. Here's how I accomplished this on my development system running Fedora Core 7 (FC7).

  1. view your PHP info via phpinfo() and check your PHP version and also see if you are running PHP in thread-safe or non-thread-safe mode since this will determine the version of the ioncube loader you need to install.
  2. If all your extensions are loaded directly from your php.ini file (whose location you'll also see on your phpinfo output) then you can simply make sure the following lines appear before any extensions are loaded (your versions and locations may differ):
    • zend_extension = /usr/lib/php/modules/ioncube_loader_lin_5.1.so
    • zend_extension = /usr/lib/php/modules/dbg.so
  3. If all your extensions are loaded dynamically from a location such as /etc/php.d/
    • assuming you would normally load your dbg.so extension via /etc/php.d/dbg.ini, simply comment out the line in there that actually loads the dbg.so extension.
    • create a new file in /etc/php.d/ called something like aaaaaaioncube.ini and paste the following lines in:
      • zend_extension = /usr/lib/php/modules/ioncube_loader_lin_5.1.so
      • zend_extension = /usr/lib/php/modules/dbg.so
    • By naming the ioncube.ini file something like aaaaaaioncube.ini it should theoretically load first, then we simply include the dbg.so line immediately after it to ensure that it loads next.

I hope this saves you a few hundred hours of frustration and gives you back the access to your debugger you should never have had problems with in the first place. If not, blame the people who encode their PHP source for use with "open source" PHP applications. They should be tarred and feathered, and then sentenced to write Windows apps!
 
< Prev   Next >

Search

Who's Online


© 2017 www.brettbrewer.com
Joomla! is Free Software released under the GNU/GPL License.