Writing extensions

PHP is an incredibly rich language, as I hope you have come to see by reading this far - there are extensions available to perform all sorts of popular operations with external libraries that really help add power to your script without much effort.

So, why would anyone want to write their own extension? We'll be answering that question in this chapter, as well as designing and producing from scratch a new extension for PHP. Note that this entire chapter requires you have a compiler to hand so that you can compile your extension. You need to be able to compile PHP - usually this requires a Unix operating system, but if you have Windows and a Windows compiler, or Cygwin, that will do also. Otherwise, while the information here might be interesting, you will not be able to make use of it unless you can compile PHP.

Topics covered in this chapter:

  • When to write a custom extension

  • How to design, create, and test your extension

Chapter contents

  1. 20.1. Why write your own extension?
    1. 20.1.1. The C Perspective
  2. 20.2. Before we begin
  3. 20.3. First steps
  4. 20.4. Hello world - in C!
  5. 20.5. C Hello World v2
  6. 20.6. Factorials in C
  7. 20.7. Extensions Conclusion
  8. 20.8. Summary
  9. 20.9. Further reading
  10. 20.10. Next chapter

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Why write your own extension? >>

Previous chapter: Next chapter

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.