DEV Community

Fris
Fris

Posted on • Edited on

Would a compiled version of PHP be great

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.

Latest comments (23)

Collapse
 
matthewbdaly profile image
Matthew Daly • Edited

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.

Collapse
 
sam_ferree profile image
Sam Ferree

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.

Collapse
 
einenlum profile image
Yann Rabiller • Edited

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".

Collapse
 
joshualjohnson profile image
Joshua Johnson

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

Collapse
 
shubhamsinha profile image
Shubham Sinha

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, dev.to, hackernews some random guy posts this kind of question and developer communities jump to thrash / defend programming languages.

Collapse
 
kip13 profile image
kip

Collapse
 
michaelgv profile image
Mike

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.

Collapse
 
adhocore profile image
Jitendra • Edited

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?

Collapse
 
rhymes profile image
rhymes

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.

Collapse
 
kip13 profile image
kip

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.

Collapse
 
kepta profile image
Kushan Joshi

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

Some comments may only be visible to logged-in visitors. Sign in to view all comments.