12 ms·
The Rise of Hybrid PHP: Blending PHP with Go and Rust
- honorary-hickup 1y agohttps://web.archive.org/web/20250830192339if_/https://yekdeveloper.com/p/4-the-rise-of-hybrid-php https://web.archive.org/web/20250830192339if_/https://yekdev...
- colesantiago 1y agoI bit the bullet rewriting my app from PHP to Go and it paid off for my company, we're talking 20K lines of PHP code, reduced to 4K lines of Go and with the added efficiency gains with it. I think some orgs just need to take the jump and plan a rewrite, add tests (easier with Go) and just do this if they are a PHP shop, I would say it's worth it. Instead of blending Rust/PHP or Go together and having an unmaintainable mess of a codebase.
- NeutralForest 1y agoBut the question always is: was the rewrite the reason for the gained efficiency, or the new language?
- colesantiago 1y agoBoth. Go made this worth it and it also was easy to hand over to another experienced developer.
- NeutralForest 1y agoFair, what did you find in Go that you couldn't in PHP? Do you miss anything from PHP?
- criemen 1y agoHow did you reduce LoC with a move from PHP to go? Go is a pretty verbose language, whereas for me PHP is somewhere in the middle of the pack in terms of verbosity (Haskell would be on the terse side, enterprise Java and Go on the verbose end, particularly due to the constant error-checking after every function call).
- yurishimo 1y agoMaybe they mean with dependencies? There are some bloated libraries out there but because PHP is a dynamic language, the bloat only matters if it’s in your hot path. But I would say a 20k line PHP app is pretty small… we probably have 20 different 1k+ files in our app. They’re not pretty but they’re still fast enough and they work so I’m not gonna try and rewrite them just for giggles. That said, when working on this legacy behemoth, it’s not uncommon we find a way to delete a few hundred lines because there are so many old features that aren’t needed by the business anymore so we can remove that cognitive load from codebase. Maybe that had a similar experience and the rewrite was just a good time to get buy in from the business to admit that the features weren’t important anymore. We run an e-commerce site so there are lots of little marketing experiments cluttering the app and it’s a constant churn to remove old ones and add new ones for people to tweak and test with feature flags. Removing dead code is just a part of the job.
- tayo42 1y agoSurprised you made it more compact and not have it turn into 40k lines of if err! = nil Ive done do rewrites of stuff in python and it gets really verbose, plus dependency injection patterns for testing.
- benjiro 1y agoA ton of stuff in PHP is mostly templating + DB calls for a lot of websites. If you combine Go + Templ for instance, your "if err" are mostly on the DB calls. What you needed to check in PHP anyway. Yes, the if err != nil is extreme frustration when your doing for instance, type conversion. But if your already doing this with reflection in your DB calls (by casting to the correct types in your struct), that saves a ton. Same with getting external data, casting it directly to structs and if something is wrong, its a single "if err". And if your just doing PHP style programming in Go, well, _, ignoring errors like PHP does and you can panic/recover to make Go act as badly as PHP, to save on the "if err". ;-)
- coolgoose 1y agoI fail to see how you got 5x lower loc from php to go. Php isn't perfect but it has a lot of shortcut syntaxes that go just doesn't have
- deleted 1y ago[deleted]
- avan1 1y agoi don't recommend rewrite in anycase (had done 2 successful rewrite before but still i don't choose that my self) and new php run times can may be really fast. you can checkout benchmarks. swoole for instance if used with all the functionalities like its specific caches may be so fast (in some cases as fast as Go)
- ok123456 1y agoIt turned out that dlopen was the "microservice" architecture we needed all along.
- hu3 1y ago> In short, the modern PHP ecosystem gives us the best of both worlds: the ability to build quickly and confidently in PHP, while still having powerful options (C, Rust, Go) for performance-critical parts. This hybrid approach lets us stay productive without sacrificing speed where it matters most. I understand this for a large codebase where rewriting is not feasible. But if that wasn't the case, a C# APIs achieves both speed of development and execution in my experience. You'll rarely need to reach for C++ or Rust. PHP is great but the language still doesn't allow things like typed arrays. It will happily accept string in a array of dates, for example.
- honorary-hickup 1y ago> It will happily accept string in a array of dates, for example While completely true, you are using static analyzer anyway which won’t let you do this. The generics support will likely come in the near future, there has been momentum in it again: https://thephp.foundation/blog/2025/08/05/compile-generics/ https://thephp.foundation/blog/2025/08/05/compile-generics/
- s1mplicissimus 1y agoI'm working in PHP for about 15 years by now, and for about 10 of them I was promised generics. In favor of your health, don't hold your breath.
- ThinkBeat 1y agoHaving been in the C# world for a long time, and the various web/api frameworks. PHP is really nice if you dig into it, it includes so many great functions and functionality built in for creating web stuff. It also has a number of issues,. but to quikly put something together PHP take the win in my limited opnion.
- reactordev 1y agoThe only reason PHP still exists is because of shared hosting companies and Wordpress. PHP’s initial appeal was you could do scripting on the server side, “turn off PHP with a ?>” spit out normal html, and “turn back on PHP with a <?php”. For a beginner programmer, it was simple, easy to understand, and had an include so your designs were’t nested table hairball messes of garbage. (but your CSS was definitely garbage). Today, it’s so easy to run JavaScript, I can build a basic jsx site in under an hour, just like I can with PHP and includes. With Bun, I can quickly write a data access layer as well and wire up crud APIs w/ JWT auth. A weekend project in both.
- thr0waway001 1y agoGood to see PHP still trucking.
- porker 1y agoPHP's FFI support is a feature that's 2/3 there and isn't seeing improvements. It makes me miss Python's cffi.
- dingdingdang 1y agoBet you don't miss Python's massively lackluster performance when compared to PHP though! Nb. I use both for diff things (good luck instrumenting ai stuff with PHP!) but the fact that I have to reach for C extensions for python to even get a basic loop to run at reasonable speed remains peculiar/scary for me.
- dakiol 1y agoThe one thing I don't like about PHP is that the whole application is bootstraped (and autoloading and the configuration is re-evaluated) in every single http request. Sure thing there's cache and all, but it just doesn't feel right (compared, to, for instance, an http server written in golang)
- klaussilveira 1y agoThere are well documented and production-ready libraries that you can use to run your own servers with PHP alone, no need for fpm or mod_php. PHP's JIT is pretty impressive and you would be blown away by the results. https://reactphp.org/ https://reactphp.org/ https://www.php.net/manual/en/book.ev.php https://www.php.net/manual/en/book.ev.php https://bitbucket.org/osmanov/pecl-event https://bitbucket.org/osmanov/pecl-event https://www.workerman.net/ https://www.workerman.net/
- duskwuff 1y agoIt doesn't have to be. Some PHP runtimes allow an application to run in a mode where a single script execution processes multiple HTTP requests: https://frankenphp.dev/docs/worker/ https://frankenphp.dev/docs/worker/
- mhsdef 1y agoThis is one of the things I do like about PHP. Intrinsically minimized state (to a certain degree).
- PetahNZ 1y agoThis is one of the best things about PHP IMO. It makes it very easy to scale out.
- bornfreddy 1y agoYup. No shared state by default.
- const_cast 1y agoIt also makes it much easier to debug and forces the complexity down.
- klaussilveira 1y agoPasir is like frankenphp, but in Rust. Very promising, but still early in development: https://github.com/el7cosmos/pasir https://github.com/el7cosmos/pasir Which uses the following Zend API bindings for Rust: https://github.com/davidcole1340/ext-php-rs https://github.com/davidcole1340/ext-php-rs There's also all sorts of interesting experiments, like ngx-php, which basically embeds PHP via Zend API inside an nginx binary: https://github.com/rryqszq4/ngx-php https://github.com/rryqszq4/ngx-php And workerman, which has a hybrid backend of asio libraries, so you can get pretty fast runtimes: https://github.com/walkor/workerman https://github.com/walkor/workerman
- conceptme 1y agoThe complexity with debugging and maintenance seem to be overlooked, if you have the option don't do this.
- avan1 1y agothanks. but may you explain more. we just choosed frankenphp but i did't see if it makes debugging it much worse.
- pancsta 1y agoWorking with 3 intersecting stacks is more complex than a single stack. Go toolchain is batteries included and coherent. Author admits to not using it bc of legacy (and preference).
- avan1 1y agoauthor here. as i mentioned in post i said we choose frankenphp since it's already supported by php foundation and in some cases we might use Go php extensions. i know writing extensions in any language add a bit complexitiy but i believe if the extensions selected wisely they will be somehow fire and forget. for instance creating pdf files would be faster in Go than php. you can create an pdf creator extension and that extension would probebly work for a long time without any adding much effort to maintenance.
- maurice2k 1y agoThere's also RoadRunner, a more PHP like alternative to FrankenPHP: https://roadrunner.dev/ https://roadrunner.dev/
- preinheimer 1y agoReminds me of how Yahoo! worked back in the day. All their display logic in PHP, with the hard business logic in c extensions.
- avan1 1y agoif you know more about it, i would glad to hear which extension they did developed for business logic. i used a lot of Yahoo! in back days.
- trog 1y agoVery curious what sort of workloads are being talked about here that have the intensity that have C or Rust or Go extensions are necessary? I can certainly believe they exist but I'd be really interested to find out more and why it makes sense to add this complexity into the stack and not solve in other ways.
- osigurdson 1y agoSometimes I think we should go back to basics: pixels, data, latency / bandwidth. The web is an optimization problem in the sense that we want to render correct pixels at perceptual speed given latency and bandwidth constraints. It should be more like: what pixels is the user about to see? What data is need to set the the pixels? What data is likely needed next and optimistically pre-fetch - something like that.
- singinwhale 1y agoThinking about user seeing pixels is seeing just a part of the picture. As all software projects you don't optimize just for immediate user experience but also development time. Time to first draw rarely coincides with development time.
- redwall_hp 1y agoAnd I don't care about pixels; I want to see structured documents. How I choose to view those is my business.
- osigurdson 1y agoGot it, you don't care about how the sausage is made. That's totally fine.
- networked 1y agoIt doesn't sound like this is what redwall_hp meant; it sounds like what they meant was that pixels are the wrong level of abstraction. If so, I agree: the web is about marked-up text. When you break it down to the very basics, what you get is a teletype, not raster.
- osigurdson 1y agoI'd say that is more like a terminal than a browser. Regardless, what I really mean is some data is needed for the pixels (or whatever abstraction you want above that). You don't need data for anything other than the current viewport and whatever is likely needed next. No less, no more. No over or under fetching. This would be much better imo.
- 1a527dd5 1y agoJoined {{company}} when everything was using 5.4, there was a big distaste of PHP back then. But as PHP have released newer versions I'm convinced our migration away from PHP (which is just finishing) is probably a step backwards _now_ that PHP is awesome. Everyone still thinks it is like 5.x days, it really isn't.
- criemen 1y agoI'm not so sure: If you think about hiring talent, there's a perception in the wider industry about PHP (rightly or wrongly, let's not debate that here) that'll prevent access to a lot of great developers. So even if not warranted anymore on technical merits anymore, in terms of employer branding, I'd say migrating away from PHP is helping.
- adamors 1y agoRight on, I wrote a lot of PHP 15 years ago and I swore I’ll never get back to it. I’m a much better developer now and I’ll actively avoid any company doing PHP in 2025.
- const_cast 1y agoPHP is a very different language than 15 years ago, and large applications are pretty much indistinguishable from Java or dotnet. The type system is more cohesive than JS or even Python at this point.
- adamors 1y agoBut still, why would I work with it? The language is crap, I guess now there are enough abstractions to hide it but they can do only so much. You're still writing $variables and calling the array_* methods etc. at some point. I'd rather work with languages that don't have this legacy crap with them. I also avoid Perl fwiw.
- const_cast 1y ago
- liampulles 1y agoI'm starting to build a bit of antagonism to all-encompassing frameworks (e.g. Spring, Larvel, Phoenix, etc.), because while they are productive to build new things with, I seem to always have the same issue on legacy projects built with them. It always seems to be a challenge to upgrade dependencies for these projects. Its usually because (in building the thing) one can't fully follow the "prescribed" way of doing things with the god framework, because each project has to deal with a niche infrastructure environment and/or business context that requires some hack or additional dependency. Then when you need to, say, upgrade a language version, you can't follow the god framework's guide for doing this (if there even is a decent one) because it will break your workaround. So you end up with this hodgepodge which never gets updated until it reaches a critical point where it cannot continue to run on your infrastructure, and it forces a big migration project. Using a selection of libraries to build up the elements of a web service, and creating your own high-level abstractions for utilizing them, does require an additional time investment, but it leaves you in more control to do upgrades piece by piece, and to pivot the way things work when it is needed. I feel like the Go ecosystem follows the latter approach more than most, and it was bit of a mindset shift for me at first, but I've grown to appreciate it.
- fozdenn 1y agoYep, In my domain only Go/Rust are useful. The opinionated framework culture never fits the bill. I think Rails/Laravel/Django are great when you have a beaten path for relational DB crud.
- tombert 1y agoWeb frameworks for me are one of those things that's "great until it isn't". If you're making a simple app then web frameworks can feel downright magical (like the original "Build a blog in 15 minutes with Rails" demo [1]), but for anything that gets even remotely complicated, I find that they generally just get in the way. I personally have grown to prefer the "mid-level" HTTP setups, like Express with Node.js or Vert.x with Java. [1]
- networked 1y ago[1] https://www.youtube.com/watch?v=Gzj723LkRJY https://www.youtube.com/watch?v=Gzj723LkRJY
- forgotmypw17 1y agoI do this with Perl. One of the reasons I like Perl is because of its high committment to backwards compatibility. I like PHP because it's so easy to set up an installation of my app, but the breaking changes have bit me hard in the past, so I try to minimize its use. Together, it's a great combo.
- phplovesong 1y agoHow is php easy to setup?
- forgotmypw17 1y agoStep 1: Copy the files. Step 2: (There is no step 2.)
- phplovesong 1y agoThis is not realistic. I have not seen that since little league soccer homepage back in the late 90s. For "simple" deployment you need a binary that you ship. Anything else requires more steps, php included.
- forgotmypw17 1y agoI don't understand the difference between one binary and several files, except that the files are easier to version...
- sublinear 1y agoThis sounds absolutely disgusting to maintain. Where are you going to hire devs that want to work on crap like this?
- avan1 1y agoas i mentioned we just choosed frankenphp which is officially supported by php foundation. also only less than 5 percent of our code base is in Go. i don't see any problem to hire developers.
- 77pt77 1y agoThe fact that we're still pretending PHP is a valid solution for almost anything after all these years is a joke. Not only that, but now we have these "frankenstein" solutions with all the interop problems on top of PHP. Just shows that as a species humans really can't learn.
- phendrenad2 1y agoPHP really isn't that different from Ruby or Python these days. But, I can see the perspective where none of those 3 are valid solutions given newer better options like NodeJS and Rust.
- sneak 1y agoYeah, I use php colab all of the time to run numpy stuff on gpus, I learned about it in my php data science class in university. They’re basically equivalent now.
- phendrenad2 1y agoYou're right, there is one area where Python has an advantage over PHP, but it has nothing to do with the language, really, and more to do with tools people have built to transform the language for other purposes. So it's sort of like saying Python and Ruby are completely different because Rails exists for one and not the other.
- 77pt77 1y ago>I learned about it in my php data science class in university. I rest my case...
- phendrenad2 1y agoAh, another data scientist, I should have known.
- const_cast 1y agoNodeJS is, like, 10 steps back from PHP 8. Worse type system, less safe, package ecosystem is a hot mess, slower... I mean the list goes on and on. We can "lipstick pig" a lot of those problems by using typescript or whatever, but now we're compiling JS and the output isn't even fast. At that point use a competent compiled language like C# or Rust.
- vadepaysa 1y agoI owe a large part of my career success to PHP when I learned it back in the day. But recently I picked it up because I had to do some maintenance work and The package management experience was really, really bad. I really think there's a big opportunity for somebody to create the astral.sh for PHP. With a proper package manager, PHP can do way more than what it presently can.
- porker 1y agoWhat did you find bad about composer?
- deleted 1y ago[deleted]
- sneak 1y agoWhen I do stuff like this, I just write the front app in the new/fast language, then reproxy the stuff not written in the fast language to the legacy app. You can even add middlewares or caching or metrics in the new app for requests going to the old one, as you can run (fast) code around both the request and the response. It’s the best of both worlds - the new app gets to see all of the traffic, but doesn’t need to implement 100% of the routes. Any added to the new app can just take precedence over the old one, carving out the path-space that gets reverse proxied. It seems like doing FFI for this is overly complex; I’d rather take the small perf hit of doing another request to a different process.
- avan1 1y agogood idea, which language you choose for that ? also with frankenphp you can just write those required apis to be really fast as go extensions.
- deleted 1y ago[deleted]
- RainyDayTmrw 1y agoOne of these is not like the other. Go is also garbage collected. Embedding a garbage collected language inside another means you have two garbage collectors fighting each other.
- imcritic 1y agoFrankenPHP sounds promising, but in reality it is a weirdo: no one uses PHP without modules. Where is the list of PHP modules supported by FrankenPHP? Is it possible to compile it with some extra PHP modules? How? I see it is tightly bound to Caddy. I am not much familiar with that webserver, I would prefer nginx, but there's not a single guide mentioning if that's possible to use nginx with FrankenPHP (as a php-fpm replacement). Also, either Caddy itself, or FrankenPHP's docker image is quite opinionated in regards to using let's encrypt certificates and it is not trivial at all how to make it work via HTTP (if something external would provide SSL) or using own certificate.
- supriyo-biswas 1y ago> FrankenPHP sounds promising, but in reality it is a weirdo: no one uses PHP without modules. You usually build the modules yourself in the Dockerfile, for example for the "pgsql" module: RUN apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pdo_pgsql && apt-get remove -y libpq-dev && rm -rf /var/lib/apt/lists/* And for http, you just put the following in the Caddyfile: http://:80 { # rest of the Caddyfile directives }
- slim 1y agostatic build, is built by default with these modules : amqp,apcu,ast,bcmath,brotli,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gmp,gettext,iconv,igbinary,imagick,intl,ldap,lz4,mbregex,mbstring,memcache,memcached,mysqli,mysqlnd,opcache,openssl,password-argon2,parallel,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,ssh2,sysvmsg,sysvsem,sysvshm,tidy,tokenizer,xlswriter,xml,xmlreader,xmlwriter,xz,zip,zlib,yaml,zstd https://github.com/php/frankenphp/blob/main/build-static.sh#L76 https://github.com/php/frankenphp/blob/main/build-static.sh#...
- resonious 1y agoI tried to propose this with Ruby and Rust. We have a super old Rails monolith and want to hyper optimize just a few endpoints. Simply allowing Rust to "poison" the monolith a bit makes gradual adaption very easy. And you keep a lot of the productivity gains of monolith. But people just seemed to prefer full on network boundaries and separate services.