Tag Archive for 'PHP'

Page 2 of 3

PHP TestFest 2008

PHP.net has posted a nice overview of the PHP TestFest 2008 initiative, which aims to increase the PHP source code coverage through PHPT tests. Worldwide, the TestFest was carried out with different user groups, and of course the PHPBelgium and phpGG were also present. We arranged a meetup in Roosendaal earlier this year and with a group of 10 people, we managed to write about 40 tests! All efforts combined, there was about 10 % increase in code coverage for PHP, which was great to hear!

Actually, I found it so much fun and rewarding to help PHP as a whole in this new way, I decided to continue contributing tests to the submission system. You can imagine I was quite excited when the PHP-QA team actually asked me if I was interested in commit access to the PHP source tree! It’s a great way to give back to the community, and apparently I got mentioned for this in the php.net article, which of course made me somewhat proud ;-)

It was very cool to see the collaborative work around the world being rewarded with our favourite pets, and no less than 4 people from Belgium and the Netherlands (Michelangelo van Dam, Stefaan Koopmanschap, Rein Velt, Marc Veldman) were given an elePHPhant.

Actually I think initiatives like the PHP TestFest make this thriving and exciting community what it is right now, and it’s because of that I very much like the Emphpower initiative from Lucas Smith. To quote the mission statement: “emPHPower is a mediator and catalyst that empowers members of the community to follow their own ideas”. For example, things like the PHP TestFest could fall under the organisation of Emphpower.

I’m pretty much sure I’ll organise the next year PHP TestFest for Belgium (and the Netherlands), under the PHPBelgium / phpGG umbrella of course ;-) Testing is one of many great ways to engage in the PHP community, and the only thing you need to know is how to write PHP code. After all, most of you who are reading this probably know how :-) More information can be found on the PHP-QA website.

PHP TestFest 2008 on PHP.net” screenshot on flickr.

Generating PHP test coverage and ccache

Today I had a weird error while generating PHP code coverage for PHPT tests. If you’re writing PHP extensions, it’s quite common to use compiler caches like ccache. They cache compile results in a way that speeds up multiple compilation of the same source, something which happens quite a lot if you’re working on coding some C extension. So I have cc, gcc and g++ dynamically linked to the ccache binary, which does the caching after proxying the compile request to the actual compiler. This works great, but when generating GCC code coverage (gcov), things don’t work as expected. When running make lcov, the following happened at the end:

Generating php_lcov.info
Capturing coverage data from lcov_data/
Found gcov version: 4.1.2
Scanning lcov_data/ for .gcda files ...
ERROR: no .gcda files found in lcov_data/!
make: *** [php_lcov.info] Error 255

The .gcda files are the ones which contain the useful coverage data used by lcov, but they just weren’t there! It took a while to figure out that disabling ccache fixed the problem. Actually the problem itself isn’t fixed, so if anyone has any idea why ccache and gcov data don’t like eachother, let me know in the comments! But for now, at least there’s a way around it, just disable ccache :-)

Dutch PHP Conference 2008, afterwards.

I just got back from the Dutch PHP Conference at the RAI in Amsterdam, and I had a great time! The 2 days conference (organized by the great people of Ibuildings and Zend) in Amsterdam were packed with fun stuff, interesting talks and people, and a cool football match (although I’m totally not into sports :-))

At thursday evening, we arrived in Amsterdam by car and first checked into our hotel. Afterwards there was still some time left to go to the city centre, so we did a bit of sightseeing. We knew quite some guys were going to a place called Fidelio, so after a good meal we went over there. As it was pretty late then, quite some people were already gone, but we still found Sebastian, Lorna, Derick, Scott, Stefan and some PHP London guys over there. It was closing time soon, so we decided to go to the hotel then.

Next day I chose the Zend Framework tutorial by Matthew Weier O’Phinney. After a short introduction and an overview of the Framework, we looked a bit deeper into specific components of the framework. Topics that were covered are how to use and write action and view helpers, the plugin architecture, extending Zend Framework classes, creating custom decorators, validators and filters, forms, how to test your code and much more! Matthew is a great speaker and the tutorial touched a lot of advanced topics, so it was definitely worth it :-)

That evening, there was a pre-conference social at the Werck bar in the city centre. We first went to diner at a great vegetarian place called “De Bolhoed” and got just in to see the start of the football match with the netherlands and france. At about half time, I decided to have it a bit and ended up with Matthew Weier O’Phinney, Remi Woler and Terry Chay talking about scalability issues and social network architectures. Really interesting stuff! The Dutch football players won the match with 4-1, so you can imagine a big party was about to start. We decided to take a walk to the central station so we could see (and feel) some of the victory happyness, afterwards we took the metro back to our hotel.

The last (and the main conference) day started with meeting some friends, such as Michelangelo and Andries. The first keynote by Zeev Suraski talked about a bit of history of PHP and where it is today. It was a funny and interesting talk with a lot of nice facts about PHP and the PHP community I didn’t know. Then Marco Tabini took the stage with his keynote “PHP and the taste of mayo”. After a pretty funny introduction, Marco moved on to keeping it simple in PHP (just as preparing mayo should be simple). He also talked about the revenue generated per visitor in different types of websites. As always, Marco delivered a good talk which makes you think about some topics.

After lunch, I accidentally missed Gaylord Aulke‘s talk “An Infrastructure for Team Based PHP Development”, but instead had a very interesting talk with Terry Chay. We talked about the viral workflow of a social networking site, data analysing techniques and photo cameras. Even though he states in the closing keynote he’s not a good photographer, he has very thorough knowledge on how cameras work. He’s great in explaining difficult topics in a way you actually could understand it :-)

Next up, Lorna Michell went to the stage with her talk “PHP Deployment with subversion”. While she said in advance she was very nervous about it, she actually did great, and I very much enjoyed her way of presenting the topic. Her overview of what is possible for deploying PHP projects was nice. After all, if you throw in references to Super Mario and Nabaztag‘s, what could go wrong? ;-)

Finally, Terry Chay prepared for the closing keynote, titled “The internet is an Ogre”. After making the analogy of the internet being big ugly fat ogre with layers, he continued on Stability, Scalability, Speed and Security and why you should handle them in that order. It’s always fun to hear Terry’s ideas, and while he might use some explicit language to get his point across, I mostly agree with what he’s saying.

This was a great conference. I got the chance to meet old friends, friends I only knew from IRC or online, but also meet interesting new people. The speakers presented some new ideas and it was very cool to see PHP be so much “alive”. A big thanks to all organizers and speakers for making this possible. I can easily say it was the best PHP conference I’ve attended yet, and I’m very much looking forward to going back next year! See you!

EmPHPower for PHP

I’ve been following Lukas‘ posts and news about EmPHPower for a while now, with great interest. To quote the mission statement:

emPHPower is a mediator and catalyst that empowers members of the community to follow their own ideas

This seems like a great initiative to me. Basically with the same views and motivations, we (Mike and me) have started PHPBelgium, to advocate the use of PHP with developers, companies and educators.

While our initiative is mostly regional (Belgium and to some extent, the Netherlands), emPHPower aims to be a central place to advocate and promote the use of PHP. It wants to connect PHP Core devs, companies and end users by providing a general platform (as a mediator) for them.

I fully support such initiatives (as I’ve been doing same things but for Belgium then) and hope this works out and actually will turn into something that helps every party involved. If there is something that can be done, I’d be glad to help out. In the end, this’ll create more visibility for PHP as a serious alternative, provide a place to go to as a company that wants to use/sponsor/develop PHP, and much more. PHP TestFest is an example that I believe could fall under organization of emPHPower.

Please note that emPHPower is currently just an idea. By the end of the year, if things look feasible, Lukas will actually start and take things further for emPHPower.

If you want to have a short overview of what emPHPower aims to be, have a look at this presentation

Using DateInterval class in PHP

DateInterval is (amongst others) a relatively new addition to the date extension in PHP 5.3. It allows to describe an interval in time, and you can perform actions with that interval. Basically, it allows to calculate with dates in a very easy way, and do even more fun stuff with it.

Unfortunately no documentation exists today for DateInterval and friends, but PHP is open-source so you can easily have a peek at the code to see what’s happening under the engine. This is more or less what the documentation for DateInterval and some helper functions could look like:


DateInterval DateInterval::__construct (string $interval)

Creates a DateInterval instance, based on the interval provided.

$interval: ISO 8601 style time interval notation. (see Wikipedia)

Return Values:
Returns DateInterval object on success or FALSE on failure.


// Interval. This acutally means 3 years, 6 months, 
// 4 days, 12 hours, 30 minutes and 5 seconds.
$interval = 'P3Y6M4DT12H30M5S';
$i = new DateInterval( $interval );

This alone isn’t very exciting, but the fun stuff begins if you use some extra date functions with it:

// let's assume $i is still around from the previous example
$format = 'Y-m-d H:i:s';
$d = new DateTime('2008-01-01 12:25');
date_add( $d, $i );
echo $d->format( $format ) . PHP_EOL;
date_sub( $d, $i );
echo $d->format( $format ) . PHP_EOL;
$d2 = new DateTime('2008-01-01 12:25');
$diff = date_diff( $d, $d2 );
date_sub( $d2, $diff );
echo $d2->format( $format ) . PHP_EOL;

There’s a lot more possible (have a look at the DatePeriod class too), but that’s for another time. This is a pretty new group of classes within PHP, so expect these to expand in functionality in the future.

php|architect’s Guide to Enterprise PHP Development

There’s a new book available for pre-order on the php|architect website, titled php|architect’s Guide to Enterprise PHP Development, by Ivo Jansch of Ibuildings.

This book is great for anyone who’s interested in learning how to use PHP in an enterprise environment. It has every step on the way covered, such as planning, development tools, deployment and much more. If you’re (planning on) using PHP in your company, this book is going to prove invaluable for everyone involved in the development process, going from developers to development managers or project managers. I believe pretty much everyone involved with software development can benefit from a book like this.

Also, as far as I know, it’s the first book ever on enterprise PHP development specializing on this subject. There still aren’t that much resources available around on enterprise PHP development, so I expect this book to be very popular on the PHP developer’s bookshelf. I definitively pre-ordered mine already! ;-)

PHPT (testfest) writing resources

The PHP TestFest month is almost over and we can already probably say it was quite a success. Of course it would be great if some of the test writers continue to occasionally write a new test or two, and for this occasion, I thought it would be handy to have a resource listing of presentations, websites and pdf’s that cover PHPT testing. Although I believe this is a decent list of resources I’ve actually used myself, I’m probably missing some, so this will be a work in progress and updated once in a while. :-)

First, some of the official PHP resources on PHPT testing (pretty much all of qa.php.net is relevant here):

GCC code coverage page for PHP, which shows test code coverage for the most popular CVS branches. Some graphs and other compiling, testing and analysing information is also available:

This is the place you’ll need to go to acually submit tests if you don’t have CVS commit karma yet (it’s good for overall testing statistics too):

Next is a blog post on what Josie Messa has learned while writing tests. Interesting article which shows a lot of real code examples and issues that she dealt with while writing PHPT tests:

Slides by Sebastian Bergmann, useful to prepare yourself for writing tests. This presentation tells about what PHPT testing is all about, how to properly write tests, and how you should prepare for testfest:

This is an article I wrote, explaining a way to set up Mac OS X for writing PHPT tests. This doesn’t use the built in PHP distribution but instead prepares the OS for manually compiling and running PHP from CVS, with code coverage and all the goodies:

Presentation by Marcus Börger with pretty extensive overview on testing (and PHPT testing in specific). This is one of the most complete presentations on the subject I could find:

The blog of Zoe Slattery, which has 2 posts (and much more to come, undoubtly!) about testing PHP and PHP TestFest:

This is the official website of the PHPT testing framework:

Of course you’re best off grabbing a CVS checkout of the PHP_5_3 (or 6_dev) source tree:

In the CVS checkout of the PHP source code, there is a interesting README file called README.TESTING. It provides useful information on how to test, testing conventions, how to handle failed tests and more:

If you have questions regarding writing PHPT tests, there are several ways to go. First off, you can ask away at the IRC channel #phptestfest on irc.freenode.net. For any kind of QA or testing related question, you can also mail php-qa@lists.php.net mailing list, and subscribe to the mailing list on http://www.php.net/mailing-lists.php.

Standard core PHP 5.3 extensions

When writing PHPT tests for PHP, it’s good practice to have a conditional --SKIPIF-- block to see if the test can be skipped when some extension you’re testing isn’t available. With the PHP_5_3 CVS branch (the one you should be testing against), some new extensions can’t be disabled, so the --SKIPIF-- block isn’t needed anymore. This applies to the following extensions: PCRE, Reflection and SPL.

In fact, the following extensions can’t be disabled so you can safely test against them without the --SKIPIF-- block:

  • date
  • ereg
  • pcre
  • Reflection
  • SPL
  • standard

For completeness, a short example for a Reflection test:

ReflectionClass::isAbstract() method
// REMOVE THEM! <?php extension_loaded('reflection') or die('skip'); ?>
abstract class TestAbstractClass {}
$abstractClass = new ReflectionClass('TestAbstractClass');

Configuring PHP: --with-extension or --enable-extension?

This is a small thing that got me wondering in the past but it wasn’t until recently, when I started picking up developing PHP extensions, that I wanted to know: when does one use --with-extension and when does one use --enable-extension? The answer is easy but you just have to remember ;-)

--with-extension is used if you want to refer to an external directory or libraries, for example --with-mysql[=DIR]. The extension can’t be built without external mysql headers, thus the –with switch.

--enable-extension is used if you just need to tell PHP to enable the extension in question, for example --enable-mbstring. Mbstring support is built in with PHP, you just tell it to enable it.

You should know that, if you are building your own extension, you should only pick and use the one that is most appropriate for your extension, but never both.

Writing PHPT tests on your mac

This is a short tutorial on how to set up a Mac with Mac OS X to prepare for writing PHPT tests. This preparation includes installing some extra software that enables you to checkout and compile the PHP_5_3 branch of the PHP source without problems. Furthermore we’ll install some tools that make it possible to get an easy overview of untested PHP code with code coverage reports.

This overview assumes you’re working on the latest version of Mac OS X, being 10.5 (Leopard). Some terminal experience also comes in handy!

1. Installation of XCode

Apple’s XCode is used to create a development environment on your mac. For example, the GCC compiler, automake and other build tools are installed with XCode. Notice: you do need XCode version 3 or higher. The files needed for the installation can be found on the Mac OS X installation DVD or on the Apple Developer Connection website (http://developer.apple.com)

2. Installation of MacPorts

MacPorts is a package manager that will ease the installation, configuration and updating of open-source software on your mac. We’ll use MacPorts to install some tools that are needed in our development environment. You can find the MacPorts installation files on http://www.macports.org. By default, the MacPorts binaries are installed in /opt/local/bin. To make working with the terminal easier, we’ll add the directory to our PATH variable. Let’s open Apple’s Terminal.app and type:

# echo 'export PATH=/opt/local/bin:$PATH' >> ~/.profile
# source ~/.profile

Trough MacPorts, we’ll install a lexer used by PHP (re2c) and a tool to download files (wget):

# sudo port install re2c
# sudo port install wget

3. Lcov installation

Next up, we’ll install lcov. Lcov is a graphical front-end for gcov, a code coverate testing tool for the GCC compiler. Lcov isn’t available in the MacPorts repository, so we’ll need to install this manually:

# sudo mkdir -p /usr/local/src; cd /usr/local/src
# sudo wget http://downloads.sourceforge.net/ltp/lcov-1.6.tar.gz
# sudo tar -xzvf lcov-1.6.tar.gz
# cd lcov-1.6

Due to a non-compatible ‘install’ binary on Mac OS X, the installation can’t be completed with the -D switch. This has no implications on the actual resulting installation, but it does need to be changed to suppress the error messages:

# sudo nano /usr/local/src/lcov-1.6/bin/install.sh

Go to line 34 (install -D $SOURCE $TARGET) and remove the -D switch. Afterwards you can install lcov with the following command:

# sudo make install

4. Installing the right flex version

Now we need to install a alternate flex version. By default, Mac OS X has the flex lexical parser installed, but the installed version is not compatible with PHP. Thus we’ll install an older flex on an alternate location, which then can be used for compiling PHP:

# cd /usr/local/src
# sudo wget http://dfn.dl.sourceforge.net/sourceforge/flex/flex-2.5.4a.tar.gz
# sudo tar -xzvf flex-2.5.4a.tar.gz
# cd flex-2.5.4
# ./configure && make
# sudo make install

5. Installing the right autoconf version

If you compile PHP, you’re advised to use autoconf version 2.13. Since Mac OS X comes with autoconf version 2.61 by default, we’ll install an older autoconf version, which again can be used when we’re compiling PHP:

# cd /usr/local/src
# sudo wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz
# sudo tar -xzvf autoconf-2.13.tar.gz
# cd autoconf-2.13
# ./configure && make
# sudo make install

Let’s change our PATH variable. That way, the right lcov, flex and autoconf binaries will be found by PHP:

# echo 'export PATH=/usr/local/bin:/opt/local/bin:$PATH' >> ~/.profile
# source ~/.profile

6. Downloading the PHP source

We create a directory to put all our sources and other related files:

# mkdir ~/phptest; cd ~/phptest/

Now we can check out the PHP source code using anonymous SVN:

# svn checkout http://svn.php.net/repository/php/php-src/branches/PHP_5_3 php-src-5.3 
# cd ~/phptest/php-src-5.3
# ./buildconf

7. Compiling and testing of PHP

Everything is now set up to write PHPT tests or just explore and hack the PHP source code. If you want to configure and compile PHP, use the following commands:

# ./configure && make && make test

If you also want to enable code coverage results, use the following command:

# ./configure --enable-gcov && make && make lcov

Optional, you can also pass the TESTS variabele to the make lcov command to only run a specific test-case (of course, this speeds up compiling the PHP source):

# make lcov TESTS=ext/foo/tests/bar.phpt

Next up, have a look at the lcov_html/ directory, where you can find the HTML code coverage results. Open your browser to view the code coverage, and write some PHPT tests to increase the overall coverage!

8. Some links to get you started on testing

PHP-QA: http://qa.php.net
PHP TestFest: http://wiki.php.net/qa/testfest
PHPT: http://phpt.info/

Update (09/07/2010): I’ve updated the article to reflect the change from CVS to SVN as version control system of the PHP project.