DEV Community

Discussion on: Would a compiled version of PHP be great

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.