1. June 2008, 21:15, by Silvan Mühlemann
“unit testing is a test that validates that individual units of source code are working properly”, that’s what Wikipedia says about unit testing. That’s general knowledge.
But what motivates me even more than the increased software quality is that it saves me development time. This sounds odd as you might believe that TDD means writing more code.
Here’s a real-life example:
(more…)
11. May 2008, 12:54, by Silvan Mühlemann
For now over three years we are working with unit tests. I’d like to share some of those experiences.
As we have two frameworks in place for our website, I can compare two different strategies for unit tests.
In our homemade legacy framework we were using SimpleTest. Mainly because I read PHP|Architect’s Guide to PHP Design Patterns and Simpletest was Jason’s framework of choice.
We have a cron job running which runs all tests every hour. The results of the tests are being shown on a page. The results are also displayed in Nagios.
(more…)
11. November 2007, 18:01, by Silvan Mühlemann
After a long day of meetings and other tedious manager work the perfect way to relax is to code. The best is a mini-projects where you see your results after an hour or so. I call these tasks “Plausch-Projekte” (”plah-oosh project” =”fun projects”).
This week my plah-oosh projects were two metric tools for Ganglia. Besides Nagios Ganglia is the main monitoring tool for our cluster. We monitor something like 20 metrics like load, memory, disk usage, network activity.
Ciprian and Stefan recently built a script to monitor apache (bytes/sec, hits/sec, idle processes etc.) via the /server-status interface. Based on their work I hacked two scripts:
ganglia_mysql_metrics.php monitors multiple mysql parameters like queries/sec, slow queries/sec, threads connected:

ganglia_squid_metrics.php reports regularly about squid metrics: Requests/sec, service time, available file descriptors:

The scripts are quick and dirty code. Procedural. Not well documented. Does only read the mcast_port from the config file and ignores the rest. But it might be a good base to be used on your cluster too. Just call them every minute via the crontab.
29. September 2007, 08:44, by Silvan Mühlemann
With 125 million page impressions a month and highly dynamic content, caching is essential for tilllate.com. At tilllate, we have worked with several different caching techniques. Before we used caching, we just pre-generated the data: A nightly cron job populates a database table or generates a file containing the expensive data. Usually expensive queries, like the Most viewed pictures.
Then we are using Cache_Lite a lot. For example our homepage: If you look at the source code of our homepage you will notice the string <!--cache id a:4:{i:0;s:1:-->. This means that the page is coming out of the cache. There are a few disadvantages of Cache_Lite:
(more…)
21. August 2007, 10:33, by Maarten Manders
Writing testable code is tricky. On reason is because you have to test all of your software components individually and isolated from each other. Imagine that you’re testing your new and cool DB abstraction layer. It’s using:
- Some sort of error log
- A config component to fetch DB credentials
- Your caching layer to temporarely save stuff
- I almost forgot: It’s using PDO
Loose Coupling
Having everything tied up like this, you’re going to have a hard time testing it. After all, you don’t want to test the connected components, just your new and cool query class. That’s where Dependency Injection kicks in - along with some other patterns with cool names. The goal is to break your piece of software down to a bunch loosely coupled components and tie them together dynamically. As soon as your software is getting the Lego look and feel, you know that you’re on the right track. This is where you can use Dependency Injection for the logging component:
Does it feel Lego already? Then go on and do the same with the other 3 dependencies.
(more…)
24. June 2007, 09:53, by Silvan Mühlemann
“Ihr habt spannende Projekte, ein tolles Team, fünf Wochen Ferien… aber tut mir leid… Ihr arbeitet mit PHP… Ich möchte eher Richtung Java gehen“, hat ein Bewerber für die Software-Entwickler-Stelle seine Absage begründet.
Ich denke, das Image von PHP ist ein Problem für Unternehmen, welche PHP-Talente suchen. Erwähnt man PHP, dann kommt dem Software-Entwickler Stichworte wie “Gästebuch-Programmiersprache”, “Personal Homepage Processor”, “Spaghetti-Code”, “Sicherheitslücken in phpBB” in den Sinn.
(more…)
17. June 2007, 19:15, by Leo Büttiker
If you’re programming php for a while you know PHP has some fancy type converting stuff. Or do you know an other programing language that can do that?
The trick is simple, if you do a mathematical operation on a string, PHP tries to convert it in a number. It does the number parsing of the string from the left to the right, as long it’s a number and stop afterwards. So converting of “12 number 34″ will you just get you 12. If the string do not start with a number PHP converts it to a 0. So be careful about 100/"bags 10".
(more…)
11. June 2007, 07:31, by Maarten Manders
Tomorrow the next Webtuesday is taking place at the namics offices in Zürich, starting at 19:30. This time, Jan Lehnhardt will come for a visit and talk about CouchDb, a “distributed document database system with bi-directional replication”. For those among you who still can’t imagine what this could be, here’s a quick overview.
Thanks to Liip for sponsering his visit!
7. June 2007, 16:24, by Maarten Manders
Recently, I was wondering about a way to simplify unit test management. I finally stumbled over Zend Frameworks Test Manager and promised to report about my experiences.
What it does
In PHPUnit’s preferred testing architecture, every package and subpackage has it’s own testing suite in a AllTests.php script. Those testing suites can be hierarchically composed to build one big testing suite for your project.
ZFTestManager adapts to this architecture and scans your tests directory for AllTests.php to create a list of testing suites. It allows you to:
- list all suites
- run suites, filtered by regular expressions
- create new suites (by creating a AllTests.php skeleton)
Furthermore, it offers a configuration file with a section for each test. There, I can define DB credentials, hosts, ports, paths and so on. Quite handy to have all config settings of my tests in one single file.
(more…)
3. June 2007, 19:44, by Maarten Manders
Apparently, this hack has been around for a few months but it wasn’t before yesterday when it went all over the news: Even your browser history isn’t safe anymore. Jeremiah Grossman found a clever way to poke into a user’s browser history to check if he or she has visited a certain URI. All it takes is some Javascript code that adds a link to a URI and then checks if it has the :visited CSS pseudo-class. In fact, it doesn’t need Javascript, these guys already created a CSS version of it, exploiting the background image XSRF attack.
(more…)