Maarten Balliauw {blog}

Web development, NuGet, Microsoft Azure, PHP, ...


MyGeneration template for Zend_Db_Table

In my article on NHibernate, I mentioned MyGeneration, a tool which creates database classes / ORM classes from your database tables. Since MyGeneration uses templates to generate classes, and PHP is underrepresented, I decided to create a PHP Zend_Db_Table template, which creates the necessary Zend_Db_Table overloads for every table in your application built using the Zend Framework. Downloads and updates can be found on the MyGeneration template library:

PHP for Microsoft AJAX Library

Something really interesting has just been released on CodePlex: PHP for Microsoft AJAX Library. The code you have to use in your scripts is clean and easy, providing a full-featured PHP backend to the Microsoft AJAX Library.

The Microsoft AJAX Library is a pure-JavaScript library that's used by ASP.NET AJAX but is also available as a separate download. Because it's pure JavaScript, it's not tied to ASP.NET on the backend. PHP for MS AJAX is code to help you make use of the Microsoft AJAX Library from PHP applications. This PHP script simply exposes PHP classes as AJAX-enabled web services, just like ASP.NET applications would do.

PHP code performance tweaks

Thanks to Sam Cooper's testing, some scalability issues came up in my SpreadSheet classes. Seems PHP has some odd internal quirks, which cause performance loss that can be severe on large amounts of data. These strange things are probably caused by PHP because it uses multiple C functions in order to perform something a single C function can handle.

Here's an example I discovered in my own code:

When you have a large array, say $aNames, in_array('Maarten', $aNames) is really slow.
"Flipping" the array, making keys values, and values keys, and then using isset() seems to be roughly 3 times faster!
So, when you need to check if an element is contained by an array, use the following code:
$aFlipped = array_flip($aNames);
if (isset($aFlipped['Maarten'])) { ... }

Thanks to this optimisation when creating the internal string table in my SpreadSheet classes (a lookup table to list duplicate strings in the SPreadSheet only once), an Excel2007 file with 8000 rows is now generated in 36 seconds, instead of nearly half an hour...

The reason for this performance issue, is that PHP internally uses a hashtable to search for a specific key. So when using in_array, searching a value consists of looping every key in the array. Searching a key is lots faster, because it uses the hashtable for lookups.

Excel2007 in PHP - Project status

After a month of development, I think it's time for a status update on my PHP Excel2007 classes. 16 december 2007, I started working on these classes as a test to check how hard it could be to create Excel2007 files using PHP5.

The story about Excel2007 and PHP, got picked up by a few websites, and it seems my set of classes has been downloaded quite a number of times. This made me continue developing the basic "Hello World" example, to a set of classes which can produce Excel files like this one:

Turns out my test-case is growing into something bigger. I'll keep adding some features, and keep you informed.

The latest version can be found on CodePlex.

DataBindable Business Objects in .NET

Checkout Emmanuel Nuyttens' article on DataBindable Business Objects. It's an interesting article, focussing on the other side of data binding that I wrote an article on myself for .NET magazine.

"There has been, and still is a lot of discussion going around
of what kind of technique a developer in general should use
to represent the data from the DataLayer through the
BusinessLayer to the Presentation Layer.

In common, there are 2 main "ideas" floating around,
those who swear the "one and only object Paradigm"
(thus them who use an O/R mapping tool to map the
database fields to custom object properties),
and those who are using the intermediate of the DataSet
(typed) to present the Data in the Presentation Layer."