Creating a PHP extension in Rust
UPDATE: A few hours after posting the initial draft of this I realized my PHP benchmark was broken. I’ve since updated the PHP and Rust versions to be more fair. You can see the changes in the GitHub repo (link at the bottom).
Last October I had a discussion with one of my coworkers at Etsy about how writing extensions to interpreted languages like PHP, Ruby or Python should be a lot easier than it is now. We talked a bit about how one of the barriers to successfully writing an extension is they’re generally written in C, and it’s hard to gain confidence in C code if you’re not an expert at the language.
Ever since then I’ve toyed with the idea of writing one in Rust, and for the past few days have been playing around with it. I finally got it to work this morning.
Rust in C in PHP
My basic idea was to write some Rust code compiled into a library, write some C headers for it, use it
Continue reading →