Wed Development

MySQL, PHP, Apache, and UTF-8 Issues

UTF-8 is hell. I have run into problems with UTF-8 before (see Migrating MySQL to UTF-8 encoding).

I moved a site that was displaying fine from an old Apache server to a new Apache2 server and quickly identified that the Apache2 server was displaying odd characters.

The site is running a PHP application with a MySQL backend. The MySQL database is using latin1_swedish_ci character encoding. The old site was displaying correctly. Both the new and old site are using the same database.

So what was going on?

Debugging PHP Tip: Using the __FILE__ Magic Constant

Recently I came into a situation where a former employee had used a gateway marshaling concept and created multiple directories with the same file names (eg. www/admin/index.php. www/admin_v2/index.php). Debugging the code became problematic due to long filenames when using __FILE__. The long file paths were polluting the debug output and making it difficult to read.

I wrote a little function to return the file path based on a root directory specification. For instance if the script filename (aka __FILE__) is '/really/long/and/hard/to/read/path/www/index.php' the function will return 'www/index.php'.

This is useful for debugging calls (I use PEAR::Log) when using techniques such as:

$thisFile = getFile(__FILE__);
$log->debug($thisFile.': initializing page');

Ubuntu, Eclipse 3.4 (Ganymede), and Subclipse 1.4.4 Issue

I recently downloaded and installed the latest version of Eclipse (3.4.0 aka Ganymede) and ran into some issues when trying to get Subclipse (plugin for subversion) up and running.

Initially I was getting the following error message when accessing Windows->Preferences->Team->SVN->SVN Interface dropdown:

JavaHL (JNI) Not Available

When attempting to view a repository via the "SVN Repository Exploring" perspective I got a different error message:

Unable to load default SVN client

Determining Application Root in PHP

I have always had trouble reliably and dynamically finding what my application root was in PHP. There seemed no way to effectively determine what the application root was on the fly. I always keep my application root separate from my www root for security considerations. This knocks out using $_SERVER['DOCUMENT_ROOT'].

The Issue

Consider the following directory structure:

/path/to/domain.com
  --> app/
        --> includes/main.php        
  --> www/
        --> index.php
        --> admin/index.php
Syndicate content