Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you "compile" PHP code and upload a binary-ish file, which will just be run by the byte code interpreter?

Tags:

php

bytecode

I know that PHP is compiled to byte code before it is run on the server, and then that byte code can be cached so that the whole script doesn't have to be re-interpreted with every web access.

But can you "compile" PHP code and upload a binary-ish file, which will just be run by the byte code interpreter?

like image 319
Carson Myers Avatar asked Oct 16 '22 15:10

Carson Myers


People also ask

Does PHP compile to HTML?

PHP is a server-side scripting language. That means a PHP script is executed on the server, the output is built on the server, and the result is sent as HTML to the client browser for rendering. It is quite common to code PHP within HTML in a script.

Which server is used to compile the PHP code?

Apache web server The -dev package is required in order to build PHP.

Is PHP a compiled or scripted language?

Basically, PHP is interpreted but PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime Zend engine.


1 Answers

After this question was asked, Facebook launched HipHop for PHP which is probably the best-tested PHP compiler to date (seeing as it ran one of the world’s 10 biggest websites). However, Facebook discontinued it in favour of HHVM, which is a virtual machine, not a compiler.

Beyond that, googling PHP compiler turns up a number of 3rd party solutions.

PeachPie

  • PeachPie GitHub
  • compiles PHP to .NET and .NET Core
  • can be compiled into self-contained binary file
  • runs on Mac, Linux, Windows, Windows Core, ARM, ...

Phalanger

  • GitHub (download), Wikipedia
  • compiles to .NET (CIL) looks discontinued from July 2017 and doesn't seem to support PHP 7.

phc

  • compiles to native binaries
  • not very active now (February 2014) – last version in 2011, last change in summer 2013

Roadsend PHP Compiler

  • GitHub, GitHub of a rewrite
  • free, open source implementation of PHP with compiler
  • compiles to native binaries (Windows, Linux)
  • discontinued since 2010 till contributors found – website down, stays on GitHub where last change is from early 2012

bcompiler

  • PECL extension of PHP
  • experimental
  • compiles to PHP bytecode, but can wrap it in Windows binary that loads PHP interpreter (see bcompiler_write_exe_footer() manual)
  • looks discontinued now (February 2014) – last change in 2011

Project Zero

  • Wikipedia, IBM
  • incubator of changes for WebSphere sMash
  • supported by IBM
  • compiles to Java bytecode
  • looks discontinued now (February 2014) – website down, looks like big hype in 2008 and 2009

Bambalam

  • compiles to stand-alone Windows binaries
  • the binaries contain bytecode and a launcher
  • looks discontinued now (February 2014) – last change in 2006

BinaryPHP

  • compiles to C++
  • looks discontinued now (February 2014) – last change in 2003
like image 247
Frank Farmer Avatar answered Oct 18 '22 05:10

Frank Farmer