Getting (Re)started in C for PHP

I’ve been reading through Sara Golemon’s excellent Extending and Embedding PHP. I’m about half way through the book and I’ve already been able to do a completely useless, but functional extension for PHP.

In the vein of theoritical limits of PHP’s parsed code versus compiled code, I put together a simple hello world app and hit AB up against it to see what it could handle. They both outputted “Hello World!\n” via a function call. The result on a basic function, with no parameter, and no return is roughly a 6% gain in speed.

What was interesting was running procedural code. Doing a straight ‘<?php echo “Hello World!\n”; ?>’ in the file was actually faster to parse than using a compiled hello_world() function. I was kind of surprised with that one.

But since procedural code is not as maintainable as compiled functions and objects and you get a speed boost from compiling, I’m thinking that might be an interesting way to handle a PHP framework (and one that I don’t think has been done yet). PHP is still the place to do experiments, but once you’ve got the API locked down, I’m thinking making an extension out of that code would get you some great speed benefits. According to my thought process, things like parsing URLs, parsing code for reflection, etc., etc., should go much faster in compiled code. I guess the next step here is to create a Hello_World object and test it out - now just to get to that part of the book. :-)

One question I do have for any PHP’ers out there, do you have any recommendations on C books? I’m leaning toward either Programming in C or The C Programming Language. The former is simply because of the publisher. I’ve yet to be disappointed by a book published from the Developer’s Library (Sara’s and George’s books included); the latter I flipped through at the bookstore over the weekend and it seemed like a pretty decent book. I know enough C to make things work, but right now it’s a matter of trial and error to get some things working. If I’m going to take full advantage of the speed to be gained by a PHP extension, I’ll need to have a better fundamental understanding of the language and how it works.