We are using DB_DataObjects as the database abstraction layer for Maintain. It's a pretty convenient way to access databases, in most cases preventing you from writing ugly SQL strings at all. So far, so good.

However, when handling lots of database entries (in my case a couple of ten thousands), you might easily run into PHP's memory limit. Imagine the following scenario:

$books = DB_DataObject::Factory('books'); $books->type = 'novel'; $books->find(); while ($books->fetch()) {     do_something(); }

It will magically query your database for you, taking some memory for caching and, when you made your way through all of the returned records (what should actually happen at some time, considering that you have got a while clause here), it should destroy the cached information, setting the memory free that was used for it.

It does not.

Imagine the above code sample being inside another while() statement. It will start constantly leaking memory until it runs into PHP's memory limit. In my case, the script finally took 56 Megs of space.

The solution is to run $books->free() after you've iterated through the records, even though the associated man page claims: "DataObjects stores result sets as a private global variable, normally this is free'ed after you have run through the results, or at the end of the request.".

By that, I cut down the memory usage of my script to barely 3 1/2 megs. Sweet! :)

Update: Bug filed. Update 2: The bug was fixed and a new, stable release is available now. Go ahead and upgrade :)

Read more…

Corey and Scott blog about a letter to the editor these days which was printed in the local newspaper recently. The tag line of the letter was, that the State of Oregon should not fund the OSL with public money because Open Source Software (OSS) is bad for the principles of capitalism.

I personally think, Peter, the author of the letter, is not the only person to think like that about Open Source Software. And we should explain to those people why OSS is not "some sort of socialistic collaborative" but professional software engineering from a different point of view.

We get rid of what effectively breaks out good and secure software development, because teamwork is made more difficult if not totally prohibited: Closed source licenses. And by that, we open ourselves towards criticism, and we can achieve that some of the very best people in the world help us on our software projects. And they constantly improve them. Why? Because they can. Because they can effectively influence what happens to the software they use. Because we let them look at what's the core of the software: Its code.

And even though this sort of software is "freely available", capitalistic principles do not suffer. (Believe me one thing: IBM, HP and others would not spend a single dollar on OSS if they could not make money of it!) Even though I can download the software and play with its code, not everybody is able or willing to do so. And therefore, the "making of money" doesn't simply disappear how Peter fears. The place of making money shifts. Towards teaching people how to use the software. Towards maintenance contracts and towards personalized solutions.

Imagine, you want to have a special feature implemented in your software because it would help your 5000 employees making their everyday work. I want to see you talking to companies like Microsoft asking for a personalized feature in their software. ("Can you write me a plugin framework so that I can still use the scripts that we used before?"). And of course, people are paid for the work they do on that. But what the State of Oregon (and therefore, indirectly, the tax payer!) gets out of its money, is a boost in efficiency and security of the software they use. Every day.

The bottom line is: Please try to open yourself a little to this point of view. Try to see, that it might be more effective to collaborate on projects together rather than keeping your work for yourself. It's collaboration, not isolation, that makes innovation work.

Read more…