Friday, 29 August 2008

PHP Opcodes

For most of the last three months I have been keeping myself busy working on a project that's related to PHP and has involved looking at PHP performance.

It's been interesting and led me to try to understand a lot more about how the Zend engine works. I spent a lot of time reading some sections of the code, and using my favourite technique (yes, I'm sorry - it's printf()) to understand how things work.

After one particularly frustrating day I asked a colleague (Andy Wharmby) about the issue I was looking at. Then a miracle happened - he'd not only looked at it but had documented it (and many other things) in a set of charts.

When I read the charts a lot of things I didn't understand got clearer - so, with Andy's permission - I'm making his work available to the PHP world in case other people find them as useful as I did. You can download them in Open Office format here.

Andy asked me to make it clear that he wrote the charts almost two years ago, so there may be bits that are out of date, or even just plain wrong. If you see things that need to be fixed please send me a mail ( and I'll be happy to update the slides. Andy made extensive use of Sara Golemon's blog posts and tools written by Sara and Derick Rethans. Apart from that, like me, he used printf() and a debugger to look at the source for the engine.

I know that Gwynne is working on internals documentation for PHP, I am really looking forward to that. These charts, although very useful, are no substitute for a well written manual section!


Cyberlot said...

I am simply amazed at the number of programmers that don't know about the power of "print/echo/whatever your fav in your lang".

It makes me scream inside to see someone trying to troubleshoot an issue and they don't take 1 minute to throw in some print statements so they can follow the results in there workflow to see where the problem starts.

Of course a good ide with internal debugger that allows you to trace values can help but come on some of us just love our command line editors!

Ivo said...

Hi Zoe,

interesting documentation. What I'm curious about is the nature of the research that is behind this (the 'php runtime team' mentioned on the cover slide). Is this all for project zero? What are the main reasons for developing a custom runtime?

ivan.jovanovic said...

Hi Zoe,

great piece of documentation. I just started to dig into PHP internals using valgrind and similar tools, and this will help me a lot.

Ivan Jovanovic

shangxiao said...

lol is that a black cb 250 in your blog picture?