我知道PHP在服务器上运行之前被编译为字节代码,然后字节代码可以被缓存,这样整个脚本就不必在每次web访问时重新解释。
但是,您能否“编译”PHP代码并上传一个二进制文件,该文件将由字节码解释器运行?
我知道PHP在服务器上运行之前被编译为字节代码,然后字节代码可以被缓存,这样整个脚本就不必在每次web访问时重新解释。
但是,您能否“编译”PHP代码并上传一个二进制文件,该文件将由字节码解释器运行?
当前回答
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的编码器使其不可读。
PHP代码有几个“编译器”。它们中的大多数不支持所有PHP特性,因为这些特性必须在运行时进行解释。
我们正在使用Phalanger - http://www.php-compiler.net/ -它甚至支持那些肮脏的PHP动态特性,并且仍然能够将它们编译为。net程序集,可以作为一个独立的DLL分发。
phc允许你将PHP程序编译成共享库,这些库可以上传到服务器。PHP程序被编译成二进制文件。它以支持求值、包含和整个PHP标准库的方式完成。
在php 7中有php ini选项opcache。File_cache,用于将字节码保存到指定文件夹中。In可能对In php cli脚本有用,这些脚本被“编译”并保存在特定的文件夹中,以便优化重用。
Opcache,它不是编译,而是类似的东西。
见5.5。使用集成的OPcache模块,在共享内存中的易失性,更好的性能和php的动态原则保持不变。
http://www.php.net/manual/en/opcache.installation.php