PHP编译器BPC 6.2发布,直接编译php文件为web server!
不了解BPC是什么的可以翻看之前的文章.
简言之,BPC可以将PHP代码最终转译成C语言,然后编译成动态链接库或者可执行程序,实现 PHP Native AOT.
apache2 mod_bpc
在BPC 6.2之前,要想发布web应用,需要将php文件编译成.so,然后由BPC提供的apache2 module mod_bpc加载,借由apache对外提供服务,详见 07_mod_bpc.
althttpd/althttpd-tls
Althttpd 是 sqlite.org/ 背后的 webserver, 其简介如下:
Althttpd is a simple webserver that has run the sqlite.org/ website since 2004. Althttpd strives for simplicity, security, and low resource usage.
As of 2022, the althttpd instance for sqlite.org answers about 500,000 HTTP requests per day (about 5 or 6 per second) delivering about 200GB of content per day (about 18 megabits/second) on a $40/month Linode. The load average on this machine normally stays around 0.5. About 10% of the HTTP requests are CGI to various Fossil source-code repositories.
详见 Althttpd: The Althttpd Webserver.
Althttpd源码只有一个c文件,我们将其改造,然后将BPC最终转译出来的.c和althttpd.c编译在一起,于是一个全新的web server诞生了!
如果编译时再加上 --static
选项,那么最终交付时,就一个可执行文件,包含了 web server + php逻辑 + js/css/image等静态资源, 非常便捷!
BPC Playground
BPC官网 bpc.dev Try it Online ( BPC Playground ) 已经支持将合适的项目编译成 althttpd, 感兴趣的可以试一试!
本作品采用《CC 协议》,转载必须注明作者和本文链接
有点意思,但是这个编译出来,CLI 的是只能在 ubuntu-18.04 运行吗,CENTOS或者其他LINUX呢,我在 ubuntu 22.04 和 CentOS 下,运行官网编译出来的这个,都提示:
同问mac下怎么编译运行,开始以为是跨平台二进制,结果一看只有linux。本来想开发自己的工具箱 win下也用的。