I saw this post on Sitepoint quoting a statement by Rasmus Lerdorf which goes (according to Sitepoint) as follows:
How can you make PHP fast? Well, yo
There's an introduction to writing php extensions at http://devzone.zend.com/article/1021 (published in 2005, might be a bit outdated). You can also use tools like swig to build wrappers for existing C/C++ code.