In this workshop, you will learn how to write a PHP extension.

We will start by converting a function that we already have in PHP code into C, which we will then wrap in a PHP extension. This will show what performance benefits you can expect by converting an algorithm.

Secondly, we will then look at wrapping the data structure that the function operates on into a class, with the initial function converted to a method. And then lastly we will add multiple methods to finish up.

What You Will Learn

- How PHP's build system works.
- How PHP handlers memory management and types.
- How to write a basic extension with procedural functions and OO.
- Where extensions would not be useful.

Required

For understanding the tutorial:
- Some knowledge of C

For taking part in the exercises:
- A Linux machine or Linux VM
- Compilers installed (apt-get install php-dev, or similar)
- GIT, valgrind, and gdb installed (all through apt, or similar)

Comments

Please login to leave a comment

Eric Mann at 16:16 on 23 Apr 2024

Audio problems aside, this was a well-presented overview of how extensions work, the way they tie into the broader PHP ecosystem, and an opportunity to get hands on with a practical extension.

As someone who has dabbled in C for years but never gotten started with extensions this was a great way for me to get my feet wet!

Pauline Vos at 17:03 on 23 Apr 2024

Really enjoyed this, relatively easy to follow along and well-prepared. Of course it helps that the speaker is very knowledgeable so he could quickly adapt/resolve any snags attendees ran into. Good stuff!

I came into this talk with zero C experience, and while there was plenty that I'm sure went over my head I still walked away having learned a lot!

My brains hurts now. The tutorial itself was good. The PHP API is an absolute mess. I don't hold that against Derick, though. :-)

Greg Fox at 14:42 on 24 Apr 2024

Great talk, just what I needed to get past some issues I was having. I wish some of these macros were documented better, that seems to be the biggest barrier right now, but the talk helped push through that a lot.