PHP编译器BPC 6.2发布,直接编译php文件为web server!

不了解 BPC 是什么的可以翻看之前的文章.

简言之,BPC 可以将 PHP 代码最终转译成 C 语言,然后编译成动态链接库或者可执行程序,实现 PHP Native AOT.

how BPC works

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, 感兴趣的可以试一试!

althttpd-demo

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 5

有点意思,但是这个编译出来,CLI 的是只能在 ubuntu-18.04 运行吗,CENTOS 或者其他 LINUX 呢,我在 ubuntu 22.04 和 CentOS 下,运行官网编译出来的这个,都提示:

./hello: error while loading shared libraries: libargon2.so.0: cannot open shared object file: No such file or directory
1年前 评论
heguangyu5 (楼主) 1年前
heguangyu5 (楼主) 1年前
yangweijie

同问 mac 下怎么编译运行,开始以为是跨平台二进制,结果一看只有 linux。本来想开发自己的工具箱 win 下也用的。

1年前 评论
heguangyu5 (楼主) 1年前