我知道PHP在服务器上运行之前被编译为字节代码,然后字节代码可以被缓存,这样整个脚本就不必在每次web访问时重新解释。

但是,您能否“编译”PHP代码并上传一个二进制文件,该文件将由字节码解释器运行?


当前回答

还有bcgen (bcompiler的一个PHP7端口):

https://github.com/vjardin/bcgen/

(仅PHP7.2)

其他回答

Actually, the Just-In-Time compiler introduced with PHP 8 does in fact compile PHP. Strangely enough, it doesn't really speed up CMS based websites (e.g. WordPress), however, it does open the doors for PHP to compete with the likes of C++. For more information, see the RFC behind the JIT implementation here: https://wiki.php.net/rfc/jit. Also, Matthew Weir O'Phinney has posted a number of insightful blogs that shed light on its capabilities. Start reading here: https://www.zend.com/blog/exploring-new-php-jit-compiler.

PHP不像许多程序那样真正被编译。您可以使用Zend的编码器使其不可读。

还有bcgen (bcompiler的一个PHP7端口):

https://github.com/vjardin/bcgen/

(仅PHP7.2)

也有

PHP的(实验性的)编译器扩展,

它的目标是

在私有PHP应用程序中编码整个脚本 在私有PHP应用程序中编码一些类和/或函数 使php-gtk应用程序能够在客户端桌面上使用,而不需要php.exe。 做一个PHP到C转换器的可行性研究

扩展可从PECL。

phc允许你将PHP程序编译成共享库,这些库可以上传到服务器。PHP程序被编译成二进制文件。它以支持求值、包含和整个PHP标准库的方式完成。