Skip to content

Would a compiled version of PHP be great

ogfris profile image Fris twitter logo github logo Updated on ・1 min read  

Would a compiled version of PHP be great, that's the question that i've asked myself alot. Perhaps making softwares in PHP is pointless because the language is very, very slow but some people who doesn't know other languages than PHP would find it useful, what do you think.

twitter logo DISCUSS (28)
markdown guide

Okay, you found my trigger, here is my rant: your assumption is incorrect: PHP is not very, very, slow. Already in 2016 comparsions showed that PHP 7+ is going to be one of the fastest scripting languages. In 2018, PHP 7.2 is the current, and fast, version.

But this is not even the end: It is also incorrect to assume, PHP is always not compiled. PHP 7.+ uses optimized Operation-Code-Cache by default, which can be looked at as the compiled code. This cache got big improvements in PHP 7.2+, which makes it an even faster language, at least upon repeated execution (which is clearly given by most scenarios in which PHP is used).

PHP is not bad, they made it great again. PHP is not even slow (whatever that means) anymore. It is even fast, compared to other scripting languages. Also, consider the fact that not every slow language is bad. It is a feature, not a bug, for a scripting language to be a little slower (NodeJS, Python, R ... all slow!). It is simply not all about them microseconds.


Totally agree, PHP 7.2 is very fast and it works great. Also, php being a scripting language it has many advantages over a compiled language. When I need stuff done fast and simple (lets say a web page that consumes a public JSON API and shows it on the page) it is so much faster to do it in PHP that in .Net Core.


When was the last time you did serious PHP? Your claims are random rants at best. PHP is not very very sloooooooow, your I/O ops, DB queries are.
PHP7.2 with opcache is a breeze. There are also frameworks like phalcon, yaf etc which are probably what you meant by "compiled" (or analogous). PHP8 with JIT will be a different animal.
Have you even tried swoole?


I’ll echo the words of others: PHP is not slow.

If you create N levels of abstraction, don’t optimize, etc - you’re making it slow. I run PHP infrastructure for my customers, we service an average of 2M unique requests per day per customer, that’s per 1 pave hit, average is 15 complex pages. We do this with a homemade framework, tons of dB queries due to site builder container logic, and hardly cache anything - each machine only uses about 1 GB ram at peak. PHP is not slow, the abstractions are.


PHP 7 is much faster than previous versions. If that's not enough for you, you could use its built-in bytecode cache...?

(That basically uses a compiler.)


There is a little to none sense to compare pure language performance in a vacuum. The bottleneck is always a developer.

I once took a challenge to accomplish a relatively simple algorithm in a language of choice by my competitor faster then he in his preferred language (it was not c neither rust and I knew that.) He put me to code in PHP, using C# himself. I easily won.


Faster than previous PHP 5 but not faster than any other language lol.


Please don't compare Python to PHP for the love of god.

Why is that? Python is a hundred times uglier, but even using python people create great things.

Also, nowadays a statement “compilation will make it faster” is obsolete. 1‰ maybe. And still, that profit is negligible compared to code clarity, tooling sets and maintainability.


Facebook first released HPHPc in 2010 to transpile PHP to C++ for its website. Then they released HHVM in 2011 which is a VM with a JIT compiler the sole goal is to make PHP faster. They also created Hack which is a PHP dialect with static typing supported by HHVM.

I believe it's still how they build the Facebook website.

I think this covers your use case.


Another benefit of Hack is an implementation of asynchronous programming

Hack provides a feature called async that provides your program the benefit of cooperative multi-tasking. It allows code that utilizes the async infrastructure to hide input/output (I/O) latency and data fetching.


People talk of language and speed as if they're handling loads of Facebook, twitter etc. Btw Facebook was built on Php and still uses in some parts. If you write good clean code by following the standards even using Ruby won't matter. Plus when you scale you can always take those decisions. I also feel those devs who are emotionally too attached with their software tools, programming language, coding patterns etc shut themselves up from learning and hence their service become obsolete. As evident in the answers, before branding Php as very very slow, the guy owning this thread not even did a basic courtesy of searching Google. Be it MEDIUM,, hackernews some random guy posts this kind of question and developer communities jump to thrash / defend programming languages.


It seems this post started with kind of a troll statement (PHP being very very slow) and some people are now doing flame wars in the comments.
I'm pretty sure this kind of behavior it helps no one. If we like to be in this community it's because we care about each other and try not to repeat the same mistakes as every other tech community (hey Reddit and IRC!).

It would be very cool to stay close to the facts (benchmarking? Clever answers?) and avoid things like "Oh please, don't compare Python to PHP".


It wouldn't make very much difference at all.

It's been my experience that when an application is slow, the bottleneck is nearly always one of the following:

  • Excessive numbers of database queries (often caused at least in part by the N+1 problem)
  • Slow/inefficient queries
  • Slow or excessive requests to third party API's

These are all issues that can be resolved by refactoring queries, using eager loading, and caching responses where appropriate. A compiled version of PHP wouldn't help with these.

In addition, if you have the opcode cache enabled (which you should in production), your PHP code gets compiled into bytecode anyway, so in a sense it is compiled.

In the extremely unlikely event that you do come across a situation where the language itself is the bottleneck, it is possible to write an extension to do it in a lower-level language. I've tried Zephir before for this as it's easier than writing a PHP extension in C, but to be honest, I found it was very hard to get better performance out of a Zephir class than an equivalent PHP and not worth the effort.

PHP 7 is pretty fast (certainly fast enough for my needs) as long as you don't have other bottlenecks in your code.


look into PeachPie, They compile PHP to .NET Core IL and it runs very fast... IIRC, it's the fastest way to run PHP.


oh thanks, i've never heard of it before.


Not to devalue what PHP has done, but you're greatly underestimating the amount of COBOL code that still exists and runs the financial sector.


Let php be what it is meant for. A server side language to take in a request and issue a response.


I find these benchmarks of great help when comparing any language.

Classic DEV Post from Jul 30 '19

PublishTo.Dev: Scheduling article publishing on

Fris profile image
Freelance developer, student and a weeb.