前言
每个增加的生产机器都需要重新安装一遍相关软件,做相同的 nginx 配置以及 php-fpm 的配置, 以及维护每个生产机器的安全更新;
假如开发的应用需要一个新的扩展,可能需要人肉每台机器去增加扩展;
负载均衡器随着业务的变更升配,后面一台 Worker 机器挂掉了, 如何做运维处理?
业务的波峰波谷怎么应对才能让资源的利用率提高?
PHP 遇见 Serverless
直接使用 gd 者 ImageMagick 扩展, 实现弹性高可用的图片、水印等各种 CPU 密集型 API
直接使用 ffmpeg + 性能型实例 + 异步有状态调用完成视频剪辑合成等音视频处理业务
使用 HTTP 触发器实现的函数, 埋点到 平台, 快速实现高可用的买量业务
直接将之前基于框架(如 ThinkPHP 实现的 WEB API 直接迁移到 FaaS 平台,不用再担心宕机和运维问题了
function handler($event, $context) {
$eventObj = json_decode($event, $assoc = true);
do your thhings
....
return $eventObj['key'];
}
函数计算 Custom runtime 执行环境底层系统是 Linux,并且已经内置的 nginx/1.10.3 和 php-fpm7.4, 对于 PHP 应用,您直接使用即可
- bootstrap
- nginx.conf
- php-fpm.conf
- php.ini-production
- wordpress
...
echo "start php-fpm"
php-fpm7.4 -c code/php.ini-production -y code/php-fpm.conf
echo "start nginx"
nginx -c code/nginx.conf
...
bootstrap 详情可参考 WordPress in FC(文末附链接
比如将 wordpress 工程不作为函数的代码包的一部分,而已提前上传到 NAS 盘,只需要设置好 nginx.conf 中的 root 能知道 Web 工程即可,如上面的 nginx.conf, mnt/auto 表示挂载的 NAS 目录,mnt/auto/wordpress 则表示在 NAS 上的 Web 工程。
此时对您来说,函数再也不用变了,您可能只是需要开发新的业务代码,然后上传到 NAS 上即可 ( 者直接使用 git 直接在 NAS 操作,实现 web 工程的版本和 git 上的 commit 绑定,使用 git 实现代码的快速升级和混滚 。
但是从安全生产的角度来说,还是建议您 Web 工程变更最好和函数的变更相关联。
小结
维基百科 https://zh.wikipedia.org/wiki/PHP?
W3Techs https://w3techs.com/?
Custom Runtime简介 https://help.aliyun.com/document_detail/132044.html?
wordpress 项目 https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/wordpress/src?
WordPress in FC https://github.com/devsapp/start-web-framework/blob/master/web-framework/php/wordpress/src/code/bootstrap?
我们最后来回答下前言中提出的问题
- bootstrap
- nginx.conf
- php-fpm.conf
- php.ini-production
- myweb
| hello.php
END
ThinkPHP https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/thinkphp/src?
Laravel https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/laravel/src?
Wordpress https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/wordpress/src?
Z-BlogPHP https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/zblog/src?
Swoole https://github.com/devsapp/start-fc/tree/master/custom-function/php74?
其他更多: https://github.com/devsapp/start-web-framework
Serverless Architectures https://martinfowler.com/articles/serverless.html?
Backend For Frontend(BFF in Serverless https://www.infoq.cn/article/0btajez51ysb_qehr526?
关于Serverless 未来对前端开发影响的具体看法 https://developer.aliyun.com/article/793492?
当 SSR 遇上 Serverless,轻松实现页面瞬开 https://cnodejs.org/topic/5e394e311225c9423dcd9754?
前端开发者全栈化
提高开发效率,减少前端和后端接口同学的沟通联调时间, 后端同学只需要做好原子的接口的稳定性和可靠性即可, 数据的聚合直接由前端同学通过 BFF 实现
借助于函数即服务(FaaS 的能力,不需要再去搭建传统的 Node 应用,一个函数就可以变成一个服务,开发者可以更纯粹的关注于业务逻辑。
FaaS 以函数为单位的形式以及弹性机制,为 SSR 应用带来了天然的隔离性和动态修复能力,可以更好的避免页面间的交叉污染, 一些边界的异常场景对应用带来致命性的伤害。
无需运维、按需执行、弹性伸缩这些特性,大大降低了 SSR 应用对开发者的门槛。
附录1 https://www.infoq.cn/article/0btajez51ysb_qehr526?
附录2 https://cnodejs.org/topic/5e394e311225c9423dcd9754?
关注 , “学习” 即可获得 Serverless 技术资源包!
Powered by 小羊羔外链网 7.12.9
©2015 - 2023 小羊羔外链网
您的IP:3.235.40.122,2023-06-06 15:20:21,Processed in 0.02143 second(s).