Hudzilla.org - the homepage of Paul Hudson
Contents > Writing extensions Wish List | Report Bug | About Me ]

20.1     Why write your own extension?

This is NOT the latest copy of this book; click here for the latest version.

Even though we all know PHP is faster than a speeding ticket, can it be made to go faster? C programmers have for years trumpeted the fact that their language is extremely fast and therefore capable of handling performance-critical tasks. However, very often you will find that when C programmers really need performance, they use inline assembly code.

Author's Note: If you are running on Linux, open up your Linux kernel source (probably in /usr/src/linux), and pick what you consider to be a CPU intensive operation. I chose arch/i386/lib/mmx.c, the code that handles MMX/3dNow! instructions on compatible chips. Inside this file you will see lots of quite complicated C code, but also extended instances of assembly code wherever speed is optimal. In fact, if you change directory to the root of the Linux kernel tree, try this command:

grep "__asm__" ./ -rl | wc -l

That searches all the files in the Linux source distribution for instances of assembly, and counts the number of files that match. In 2.5.65, which has been superceded numerous times now that the 2.6 kernel is stable, the number of files in the kernel source that use assembly once or more is the rather ominous number of 666! So, C programmers using assembly is quite a widespread thing.

PHP programmers, although blessed with a naturally fast language, can also use a lower-level language for speed critical operations - although in our case, C is next on the food chain. While it is possible to use assembly code from PHP (through C, as C programmers do), there is more than enough speed improvement just switching to C, so that is what I will be covering here.

Please note that, within the extent of the space available, this is a no-holds-barred chapter - prior knowledge of C is required, knowledge of assembly would be good, and very good knowledge of PHP is mandatory.





<< 20 Writing extensions   20.1.1 The C Perspective >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
roopu_g@rediffmail.com - 13 Oct 2008

this page is good. can you give some information on smarty?



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is one plus four?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow