1fy07h 发表于 2024-10-3 15:56:44

PHP 遇见 Serverless,帮你处理这些痛点!


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/yvBJb5IiafvnbRSgXlibCZy1qX6WFquAAsyYicXC2A4Rd9VfdXiaeQibAajKg4kRG9kChCZSHsEc2CuxHdd9PO7bARw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p><span style="color: black;"><span style="color: black;">作者:罗松(西流)</span></span><strong style="color: blue;"><span style="color: black;">关注下方&nbsp;Serverless&nbsp;公众号后台回复&nbsp;</span><span style="color: black;">学习</span><span style="color: black;">&nbsp;<span style="color: black;">就可</span><span style="color: black;">得到</span><span style="color: black;">研发</span>者学习资料下载链接!</span></strong><span style="color: black;"><strong style="color: blue;">01</strong></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><strong style="color: blue;">前言</strong></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Cloud Native</span></p><span style="color: black;">PHP 的应用范围相当广泛,尤其是在网页程序的<span style="color: black;">研发</span>上, <span style="color: black;">按照</span>最新</span><span style="color: black;">维基百科<strong style="color: blue;">[</strong><strong style="color: blue;">1]</strong></span><span style="color: black;"><span style="color: black;">表示</span>,2013 年 4 月的统计资料,PHP <span style="color: black;">已然</span>被安装在超过 2 亿 4400 万个网站和 210 万台服务器上, 而<span style="color: black;">按照</span></span><span style="color: black;">W3Techs<strong style="color: blue;">[</strong><strong style="color: blue;">2]</strong></span><span style="color: black;"> 的报告,<span style="color: black;">截止</span> 2021 年 9 月, 有 78.9%的网站<span style="color: black;">运用</span> PHP。<span style="color: black;">因此</span> PHP 是世界<span style="color: black;">第1</span>语言<span style="color: black;">最少</span>在 web <span style="color: black;">研发</span><span style="color: black;">行业</span>并不是戏<span style="color: black;">叫作</span>。</span><span style="color: black;">而在技术选型上,PHP <span style="color: black;">重点</span>采用的是 LAMP(全<span style="color: black;">叫作</span>是Linux + apache + mysql + php) <span style="color: black;">或</span> LNMP(全<span style="color: black;">叫作</span>是Linux + nginx + mysql + php),这种成熟稳定的技术框架推动 PHP web <span style="color: black;">研发</span>生态的繁荣和<span style="color: black;">商场</span>上的成功。</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVLiamy1wia2XjIaDbOic3pNBcaugLPqYYcHKSykr3W88UaiborH6ltyEcng/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">在传统的<span style="color: black;">研发</span>模式中,<span style="color: black;">研发</span>者自己需要安装<span style="color: black;">守护</span><span style="color: black;">各样</span>软件的安装、<span style="color: black;">守护</span>升级:</span><span style="color: black;"><span style="color: black;">倘若</span>您是一个<strong style="color: blue;">企业用户</strong>,<span style="color: black;">倘若</span>业务体量变大<span style="color: black;">或</span>为了生产环境的稳定和可用性,<span style="color: black;">运用</span>负载<span style="color: black;">平衡</span>是一个必然的选项:</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVffjyuNHwtMqng0lrhcHLyLVcEfzP9xVicZDu7Is6ugNgiaYwia8VPUycQ/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">即此时,PHP <span style="color: black;">研发</span>者<span style="color: black;">或</span>线上运维的<span style="color: black;">朋友</span>关心的事情多了起来:</span><span style="color: black;"><span style="color: black;">每一个</span><span style="color: black;">增多</span>的生产<span style="color: black;">设备</span>都需要重新安装一遍<span style="color: black;">关联</span>软件,做相同的 nginx 配置以及 php-fpm 的配置,以及<span style="color: black;">守护</span><span style="color: black;">每一个</span>生产<span style="color: black;">设备</span>的安全更新;</span><span style="color: black;">假如<span style="color: black;">研发</span>的应用需要一个新的扩展,可能需要人肉每台<span style="color: black;">设备</span>去<span style="color: black;">增多</span>扩展;</span><span style="color: black;">负载<span style="color: black;">平衡</span>器随着业务的变更升配,后面一台 Worker <span style="color: black;">设备</span>挂掉了,<span style="color: black;">怎样</span>做运维处理?</span><span style="color: black;">业务的波峰波谷怎么应对<span style="color: black;">才可</span>让资源的利用率<span style="color: black;">加强</span>?</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>您是</span><strong style="color: blue;">项目组<span style="color: black;">研发</span>成员比较多的企业用户</strong><span style="color: black;">,能<span style="color: black;">不可</span>不需要给<span style="color: black;">每一个</span><span style="color: black;">研发</span>配置一个安装的 NLP 的 Linux <span style="color: black;">设备</span><span style="color: black;">做为</span><span style="color: black;">研发</span>测试<span style="color: black;">设备</span>(<span style="color: black;">或</span>多人共享一个<span style="color: black;">设备</span>)?</span></p><span style="color: black;"><span style="color: black;">倘若</span>您是一个<strong style="color: blue;"><span style="color: black;">供给</span>网站<span style="color: black;">研发</span>和托管的 ISV</strong>、外包<span style="color: black;">机构</span><span style="color: black;">或</span>创业<span style="color: black;">机构</span>,我的客户都是<span style="color: black;">有些</span>中小企业的门户网站,我怎么<span style="color: black;">加强</span>我后端<span style="color: black;">设备</span>资源利用率以及更好<span style="color: black;">供给</span>定制化服务?</span><span style="color: black;"><span style="color: black;">倘若</span>您是一个<strong style="color: blue;">学生<span style="color: black;">或</span>准备学习 PHP <span style="color: black;">研发</span></strong>,本地<span style="color: black;">仅有</span> Windows 电脑,能<span style="color: black;">不可</span>直接近乎免费的方式获取 LNP(Linux+Nginx+PHP) 的环境用来学习呢?</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">带着这些问题, <span style="color: black;">咱们</span>去探索一下 Serverless 是<span style="color: black;">怎样</span><span style="color: black;">处理</span>这些痛点的。</span></p><span style="color: black;"><strong style="color: blue;">02</strong></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><strong style="color: blue;">PHP 遇见 Serverless</strong></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Cloud Native</span></p><strong style="color: blue;">1</strong><span style="color: black;">&nbsp;什么是 Serverless?</span><span style="color: black;">Serverless = Faas (Function as a service) + Baas (Backend as a service),<span style="color: black;">咱们</span>简单<span style="color: black;">经过</span>两个图快速<span style="color: black;">认识</span><span style="color: black;">关联</span>概念:</span><strong style="color: blue;"><span style="color: black;">传统模式</span></strong><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVrXU8M2KJfgxS44scJayXQwce9NlKKiaxQHvAE1Cdia8dnmic3cKtYV2HA/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><strong style="color: blue;"><span style="color: black;">Serverless 模式</span></strong><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CV7ibicBUKwhgY6pXk9X4VsUlAuiaLSicpLa3aibjo9uEy8AQSkjJuN1dzwww/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">图中的 CDN 和 OSS <span style="color: black;">便是</span> BaaS 服务,FC <span style="color: black;">便是</span>自定义函数<span style="color: black;">规律</span>的 FaaS 平台, <span style="color: black;">经过</span>这个对比,<span style="color: black;">咱们</span>能快速得到 FaaS 的特性和好处:</span><span style="color: black;">只需要专注业务代码<span style="color: black;">研发</span>, 编写对应的<span style="color: black;">规律</span><span style="color: black;">就可</span></span><span style="color: black;">极致弹性伸缩, 无需管理服务器</span><span style="color: black;">按量付费,每次调用按毫秒计费</span><span style="color: black;">...</span><span style="color: black;">本文后续讨论的 Serverless <span style="color: black;">重点</span>指的是 FaaS,如下示意图,几行代码编写完毕,<span style="color: black;">保留</span>到云厂商的 FaaS 平台,就完<span style="color: black;">成为了</span>一个弹性高可用的 Web API。</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CV8FLw6cuFweGUACp2qRzRDQqDOLMPXwtuwlTZMTsw4snP4BeGH544DQ/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><strong style="color: blue;">2</strong><span style="color: black;">&nbsp;PHP 遇见 Serverless</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP <span style="color: black;">做为</span>一个<span style="color: black;">研发</span>群体的很大的语言,各大云厂商的 FaaS,<span style="color: black;">例如</span>阿里云的函数计算、AWS 的 Lambda (<span style="color: black;">经过</span></span><span style="color: black;">Custom Runtime<strong style="color: blue;">[</strong><strong style="color: blue;">3]</strong></span><span style="color: black;">间接支持)、腾讯的 SCF 等都推出了对 PHP 语言的支持,phper 面对前端<span style="color: black;">行业</span>的 Serverless 技术革新实践(感兴趣的见本文最后的附录),应该不遑多让。以阿里云函数计算为例,有<span style="color: black;">非常多</span> PHP 的<span style="color: black;">研发</span>者有了<span style="color: black;">非常多</span>有趣的实践:</span></p><span style="color: black;">直接<span style="color: black;">运用</span> gd <span style="color: black;">或</span> ImageMagick 扩展,实现弹性高可用的<span style="color: black;">照片</span>、水印等<span style="color: black;">各样</span> CPU 密集型 API</span><span style="color: black;">直接<span style="color: black;">运用</span> ffmpeg + 性能型实例 + 异步有状态调用完成视频剪辑合成等音视频处理业务</span><span style="color: black;"><span style="color: black;">运用</span> HTTP 触发器实现的函数, 埋点到<span style="color: black;">宣传</span>平台, 快速实现高可用的买量业务</span><span style="color: black;">直接将之前基于框架(如 ThinkPHP)实现的 WEB API 直接迁移到 FaaS 平台,<span style="color: black;">不消</span>再担心宕机和运维问题了</span><span style="color: black;">虽然 FaaS 很好地<span style="color: black;">处理</span>了 phper 如下问题:</span><span style="color: black;">新业务<span style="color: black;">或</span><span style="color: black;">研发</span>新的 web API</span><span style="color: black;">存量业务中, 有些 CPU 密集型<span style="color: black;">或</span>弹性<span style="color: black;">需求</span>很高的 API 单独抽离出来 FaaS 化</span><span style="color: black;"><span style="color: black;">然则</span>传统的<span style="color: black;">研发</span>模式<span style="color: black;">或</span>存量业务,对<span style="color: black;">研发</span>者有<span style="color: black;">必定</span>的上手和改<span style="color: black;">导致</span>本,<span style="color: black;">例如</span>某 Faas 厂商 PHP Runtime 编程接口示例:</span><span style="color: black;">function handler($event, $context) {</span><span style="color: black;"> $eventObj = json_decode($event, $assoc = true);</span><span style="color: black;">// do your thhings</span><span style="color: black;"> // ....</span><span style="color: black;"> return $eventObj;</span><span style="color: black;">}</span><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">然则</span>能<span style="color: black;">不可</span>更进一步,<span style="color: black;">研发</span>者不需要<span style="color: black;">根据</span> FaaS 厂商的约定的函数入口能实现一个个的API, &nbsp;而是能直接将传统运行在 LAMP <span style="color: black;">或</span> LNMP 的项目直接 FaaS 化?</p>
    </span><span style="color: black;">答案是肯定的。</span><span style="color: black;">阿里云函数计算的 Custom Runtime 以及直接基于 HTTP 协议的极简编程模型走在了所有云厂商的前列。</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVa0XvCXnQz7JwnvjLXywV3ctQBciaxO5dYVjcj6YqMRWDia5LBrkEQE4w/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">函数计算<span style="color: black;">起步</span> Custom Runtime 执行环境时,会默认调用 bootstrap 文件(<span style="color: black;">或</span>您创建函数的时设置的 Args 参数)<span style="color: black;">起步</span>您自定义的 HTTP Server,<span style="color: black;">而后</span>这个 HTTP Server 接管了函数计算系统的所有请求,即您所有的函数调用请求。</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">函数计算&nbsp;Custom runtime&nbsp;执行环境底层系统是 Linux, 并且<span style="color: black;">已然</span>内置的&nbsp;nginx/1.10.3 和 php-fpm7.4,&nbsp; <span style="color: black;">针对</span>&nbsp;PHP&nbsp;应用,您直接<span style="color: black;">运用</span><span style="color: black;">就可</span></span></p><span style="color: black;">以<span style="color: black;">安排</span>一个 </span><span style="color: black;">wordpress<strong style="color: blue;">[</strong><strong style="color: blue;">3]</strong></span><span style="color: black;">项目为例, 只需要将如下目录直接打包成一个 zip 包在函数计算平台创建一个函数<span style="color: black;">就可</span>:</span><span style="color: black;">- bootstrap</span><span style="color: black;">- nginx.conf</span><span style="color: black;">- php-fpm.conf</span><span style="color: black;">- php.ini-production</span><span style="color: black;">- wordpress</span><span style="color: black;">其中 wordpress 目录是对应的 web 工程, &nbsp;bootstrap 是<span style="color: black;">起步</span> nginx 和 php-fpm 的脚本<span style="color: black;">就可</span>:</span><span style="color: black;">...</span><span style="color: black;">echo "start php-fpm"</span><span style="color: black;">php-fpm7.4 -c /code/php.ini-production -y /code/php-fpm.conf</span><span style="color: black;">echo "start nginx"</span><span style="color: black;">nginx -c /code/nginx.conf</span><span style="color: black;">...</span><span style="color: black;">bootstrap 详情可参考 <span style="color: black;">WordPress in FC<strong style="color: blue;"></strong></span>(文末附链接)</span><span style="color: black;"><span style="color: black;">因此</span>,<span style="color: black;">运用</span>函数计算这个 Serverless <span style="color: black;">制品</span>和传统的 PHP <span style="color: black;">研发</span>相结合后,您再<span style="color: black;">亦</span><span style="color: black;">不消</span><span style="color: black;">思虑</span>负载<span style="color: black;">平衡</span>的事情,<span style="color: black;">不消</span><span style="color: black;">思虑</span>扩缩容的事情,<span style="color: black;">不消</span>管理<span style="color: black;">设备</span>、<span style="color: black;">不消</span>担心宕机的事情等等,只需要安安心心把业务代码<span style="color: black;">研发</span>好<span style="color: black;">就可</span>。</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVnpdIAQz2ylrGeGDQ3vnTGmPeNN246vdFFFE8WtZYXMCuy21A0BiaBdw/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">从上图<span style="color: black;">能够</span>看出:<span style="color: black;">研发</span>者只需要<span style="color: black;">研发</span>好自己的业务代码<span style="color: black;">就可</span>,<span style="color: black;">独一</span>需要<span style="color: black;">思虑</span>的事情,<span style="color: black;">便是</span>函数计算这边扩容不要太多太猛(<span style="color: black;">例如</span>直接在函数计算平台设置下该函数能弹出的最大实例数目<span style="color: black;">就可</span>),给下游自己的 Mysql 数据库过大的压力<span style="color: black;">就可</span>。</span><span style="color: black;">当然, 从原始的传统的 php web 应用完全迁移到 Serverless 形态的函数计算平台,某些场景可能需要<span style="color: black;">思虑</span>数据持久化问题,<span style="color: black;">由于</span>函数计算是无状态的,数据持久化<span style="color: black;">保留</span><span style="color: black;">能够</span>借助 NAS、Redis 等服务完成,以 NAS 为例,流程图如下:</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVzo3kz1xVSHiahn4St1XlZN1z27Z5pIDnlH5BW3vkfvH7cXRJojtyJqg/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">以 WordPress 为例,后台系统上传的<span style="color: black;">照片</span><span style="color: black;">或</span> Session 功能都是需要持久化到磁盘的。</span><span style="color: black;">设置 web 工程的文件上传目录<span style="color: black;">或</span> session 目录为 NAS 盘的某个目录, NAS 盘实现持久化</span><span style="color: black;"><span style="color: black;">乃至</span><span style="color: black;">能够</span>将 web 工程直接放到 NAS 盘上,此时函数计算纯粹<span style="color: black;">便是</span> LNP 执行环境</span><img src="https://mmbiz.qpic.cn/mmbiz_png/l1DDNxlXXJeNYUB4FqQB9BONycrJ69CVM2EbfFib48aufkicyV4sUJedhj5WibvDRo1aNCOvGwcpB9tbZeCCWcdDQ/640?wx_fmt=png&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><span style="color: black;">例如</span>将 wordpress 工程不<span style="color: black;">做为</span>函数的代码包的一部分,<span style="color: black;">罢了</span>提前上传到 NAS 盘,只需要设置好 nginx.conf 中的 root 能<span style="color: black;">晓得</span> web 工程<span style="color: black;">就可</span>,如上面的 nginx.conf,/mnt/auto <span style="color: black;">暗示</span>挂载的 NAS 目录,mnt/auto/wordpress 则<span style="color: black;">暗示</span>在 NAS 上的 web 工程。</span><span style="color: black;">此时对您<span style="color: black;">来讲</span>,函数再<span style="color: black;">亦</span><span style="color: black;">不消</span>变了,您可能只是需要<span style="color: black;">研发</span>新的业务代码,<span style="color: black;">而后</span>上传到 NAS 上<span style="color: black;">就可</span>(<span style="color: black;">或</span>直接<span style="color: black;">运用</span> git 直接在 NAS 操作,实现 web 工程的版本和 git 上的 commit 绑定,<span style="color: black;">运用</span> git 实现代码的快速升级和混滚)</span><span style="color: black;"><span style="color: black;">然则</span>从安全生产的<span style="color: black;">方向</span><span style="color: black;">来讲</span>,还是<span style="color: black;">意见</span>您 web 工程变更最好和函数的变更<span style="color: black;">关联</span>联。</span><span style="color: black;"><strong style="color: blue;">03</strong></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><strong style="color: blue;">总结</strong></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Cloud Native</span></p><span style="color: black;">从上面的讨论和<span style="color: black;">描述</span>中,<span style="color: black;">咱们</span>不难<span style="color: black;">发掘</span>,PHP 遇见 Serverless 是一件令人兴奋的事情,让 phper 有了更大的想象空间。Serverless 的理念和 PHP 这个语言<span style="color: black;">显现</span>的理念<span style="color: black;">亦</span>是一致的:<strong style="color: blue;"> 即让<span style="color: black;">研发</span>者最大精力集中在自己的业务价值。</strong>PHP 语言<span style="color: black;">始终</span>是 web <span style="color: black;">行业</span>最好的生产力<span style="color: black;">表率</span>,而 Serverless 将会让 PHP 如虎添翼。</span><span style="color: black;"><strong style="color: blue;">04</strong></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">关联</span>链接</strong></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Cloud Native</span></p><span style="color: black;"><span style="color: black;"></span>维基百科:</span><span style="color: black;"><span style="color: black;">https://zh.wikipedia.org/wiki/PHP?</span></span><span style="color: black;"><span style="color: black;"></span>W3Techs:</span><span style="color: black;"><span style="color: black;">https://w3techs.com/?</span></span><span style="color: black;"><span style="color: black;"></span>Custom Runtime 简介:</span><span style="color: black;"><span style="color: black;">https://help.aliyun.com/document_detail/132044.html?</span></span><span style="color: black;"><span style="color: black;"></span>wordpress 项目:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/wordpress/src?</span></span><span style="color: black;"><span style="color: black;"></span>WordPress in FC:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-web-framework/blob/master/web-framework/php/wordpress/src/code/bootstrap?</span></span><strong style="color: blue;"><span style="color: black;"><span style="color: black;">咱们</span>最后来一一解答下前言中提出的问题:</span></strong><span style="color: black;"><span style="color: black;">Q1:</span><span style="color: black;">倘若</span>您是一个企业用户,业务体量变大<span style="color: black;">或</span>为了生产环境的稳定和可用性,<span style="color: black;">怎样</span>做?</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">A1:</span>
      </span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">如上面<span style="color: black;">描述</span>,<span style="color: black;">运用</span>函数计算和传统的 PHP <span style="color: black;">研发</span>相结合后,您再<span style="color: black;">亦</span><span style="color: black;">不消</span><span style="color: black;">思虑</span>负载<span style="color: black;">平衡</span>的事情,<span style="color: black;">不消</span><span style="color: black;">思虑</span>扩缩容的事情,<span style="color: black;">不消</span>管理<span style="color: black;">设备</span>、担心宕机的事情等等,只需要安安心心把业务代码<span style="color: black;">研发</span>好<span style="color: black;">就可</span>。</p>
    <span style="color: black;"><span style="color: black;">Q1:</span><span style="color: black;">倘若</span>您是项目组<span style="color: black;">研发</span>成员比较多的企业用户,能<span style="color: black;">不可</span>不需要给<span style="color: black;">每一个</span><span style="color: black;">研发</span>配置一个安装的 NLP 的 Linux <span style="color: black;">设备</span><span style="color: black;">做为</span><span style="color: black;">研发</span>测试<span style="color: black;">设备</span>(<span style="color: black;">或</span>多人共享一个<span style="color: black;">设备</span>)?</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">A1:</span>是的,<span style="color: black;">每一个</span><span style="color: black;">研发</span>者在函数计算上创建一个自己的 Service/函数<span style="color: black;">就可</span>,Service/函数配置<span style="color: black;">研发</span>测试环境的 VPC,实现内网安全<span style="color: black;">拜访</span>数据库等其他下游服务。函数调用的时候,函数计算会拉一个 NLP 的执行环境来运行您分支上正在<span style="color: black;">研发</span>的 PHP 代码。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">每一个</span>执行环境是相互隔离的</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">按调用次数计费, 不需要预留<span style="color: black;">设备</span>, 免除了<span style="color: black;">设备</span>成本上的浪费</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">亦</span><span style="color: black;">能够</span>很方便进行压测等<span style="color: black;">各样</span>事宜</span></p><span style="color: black;">Q1:</span><span style="color: black;">倘若</span>您是一个<span style="color: black;">供给</span>网站<span style="color: black;">研发</span>和托管的<span style="color: black;"> ISV、外包<span style="color: black;">机构</span><span style="color: black;">或</span>创业<span style="color: black;">机构</span>,我的客户都是<span style="color: black;">有些</span>中小企业的门户网站,我怎么<span style="color: black;">加强</span>我后端<span style="color: black;">设备</span>资源利用率以及更好<span style="color: black;">供给</span>定制化服务?</span><span style="color: black;"><span style="color: black;">A1:</span><span style="color: black;">一般</span><span style="color: black;">来讲</span>,<span style="color: black;">非常多</span>企业门户网站<span style="color: black;">拜访</span>量不大,<span style="color: black;">然则</span>网站挂掉了会<span style="color: black;">导致</span>客户投诉。<span style="color: black;">每一个</span>客户的网站<span style="color: black;">经过</span> service <span style="color: black;">或</span>函数区分,通过函数名<span style="color: black;">或</span> service 去区分您自己的客户:i. 管理方便 &nbsp;ii. 做定制化方便 &nbsp;iii. 做<span style="color: black;">区别</span> VIP 等级服务方便。举个例子,您<span style="color: black;">能够</span>快速<span style="color: black;">经过</span>某个函数的调用指标<span style="color: black;">状况</span>,<span style="color: black;">能够</span>看出哪个客户的网站<span style="color: black;">拜访</span>量大,<span style="color: black;">能够</span>做出客户画像以及制定<span style="color: black;">区别</span>的收费和 VIP 服务级别。</span><span style="color: black;">Q1:</span><span style="color: black;"><span style="color: black;">倘若</span>您是一个学生<span style="color: black;">或</span>准备学习 PHP <span style="color: black;">研发</span>,本地<span style="color: black;">仅有</span> Windows 电脑,能<span style="color: black;">不可</span>直接近乎免费的方式获取 LNP(Linux+Nginx+PHP) &nbsp;的环境用来学习呢?</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">A1:</span>是的, 只要将如下的文件和文件夹打包成 zip 包去函数计算<span style="color: black;">掌控</span>台创建函数<span style="color: black;">就可</span>:</span></p><span style="color: black;">- bootstrap</span><span style="color: black;">- nginx.conf</span><span style="color: black;">- php-fpm.conf</span><span style="color: black;">- php.ini-production</span><span style="color: black;">- myweb</span><span style="color: black;"> | - hello.php</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(END)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>您对 PHP 落地 Serverless 感兴趣,您有观点、想法<span style="color: black;">或</span>想吐槽的,<span style="color: black;">能够</span>和钉钉搜索:</span><span style="color: black;">31897696</span><span style="color: black;">,欢迎进群<span style="color: black;">大众</span><span style="color: black;">一块</span>交流。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p><strong style="color: blue;">1</strong>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">PHP 框架 Serverless 最佳实践:</span></h2><span style="color: black;"><span style="color: black;"></span>ThinkPHP:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/thinkphp/src?</span></span><span style="color: black;"><span style="color: black;"></span>Laravel:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/laravel/src?</span></span><span style="color: black;"><span style="color: black;"></span>Wordpress:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/wordpress/src?</span></span><span style="color: black;"><span style="color: black;"></span>Z-BlogPHP:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-web-framework/tree/master/web-framework/php/zblog/src?</span></span><span style="color: black;"><span style="color: black;"></span>Swoole:</span><span style="color: black;"><span style="color: black;">https://github.com/devsapp/start-fc/tree/master/custom-function/php74?</span></span><span style="color: black;"><span style="color: black;"></span>其他<span style="color: black;">更加多</span>:</span><span style="color: black;"><span style="color: black;">&nbsp;https://github.com/devsapp/start-web-framework</span></span><strong style="color: blue;">2</strong><span style="color: black;">&nbsp; 参考引用</span><span style="color: black;">Serverless Architectures:</span><span style="color: black;"><span style="color: black;">https://martinfowler.com/articles/serverless.html?</span></span><span style="color: black;">Backend For Frontend(BFF)in Serverless:</span><span style="color: black;"><span style="color: black;">https://www.infoq.cn/article/0btajez51ysb_qehr526?</span></span><span style="color: black;">关于 Serverless <span style="color: black;">将来</span>对前端<span style="color: black;">研发</span>影响的<span style="color: black;">详细</span>看法:</span><span style="color: black;"><span style="color: black;">https://developer.aliyun.com/article/793492?</span></span><span style="color: black;">当 SSR 遇上 Serverless,<span style="color: black;">容易</span>实现页面瞬开:</span><span style="color: black;"><span style="color: black;">https://cnodejs.org/topic/5e394e311225c9423dcd9754?</span></span><strong style="color: blue;">3</strong><span style="color: black;">&nbsp;附录</span><strong style="color: blue;"><span style="color: black;">Serverless 在前端<span style="color: black;">行业</span>如火如荼的发展</span></strong><span style="color: black;"><span style="color: black;">附录1</span></span><span style="color: black;">Backend For Frontend(BFF)in Serverless 来<span style="color: black;">加强</span>生产力</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">前端<span style="color: black;">研发</span>者全栈化</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">加强</span><span style="color: black;">研发</span>效率,减少前端和后端接口<span style="color: black;">朋友</span>的沟通联调时间,后端<span style="color: black;">朋友</span>只需要做好原子的接口的稳定性和<span style="color: black;">靠谱</span>性<span style="color: black;">就可</span>,数据的聚合直接由前端<span style="color: black;">朋友</span><span style="color: black;">经过</span> BFF 实现</span></p><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><span style="color: black;">附录2</span></span><span style="color: black;">当 SSR 遇上 Serverless,<span style="color: black;">容易</span>实现页面瞬开</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">借助于函数即服务(FaaS)的能力,不需要再去搭建传统的 Node 应用,一个函数就<span style="color: black;">能够</span>变成一个服务,<span style="color: black;">研发</span>者<span style="color: black;">能够</span>更纯粹的关注于业务<span style="color: black;">规律</span>。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">FaaS 以函数为单位的形式以及弹性机制,为 SSR 应用带来了天然的隔离性和动态修复能力,<span style="color: black;">能够</span>更好的避免页面间的交叉污染,或<span style="color: black;">有些</span>边界的<span style="color: black;">反常</span>场景对应用带来致命性的<span style="color: black;">损伤</span>。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">无需运维、按需执行、弹性伸缩这些特性,大大降低了 SSR 应用对<span style="color: black;">研发</span>者的门槛。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">附录 1:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">https://www.infoq.cn/article/0btajez51ysb_qehr526?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">附录 2:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">https://cnodejs.org/topic/5e394e311225c9423dcd9754?</span></p><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、</span><a style="color: black;">Spring Boo</a>t Serverless 实战 | Serverless 应用的监控与调试</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2、</span><a style="color: black;">人人都是 Serverless 架构师 | “盲盒抽奖”创意营销活动实践</a></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3、</span><a style="color: black;"><span style="color: black;">创新推出 | Serverless 调试大杀器:端云联调</span></a></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4、</span><a style="color: black;">人人都是 Serverless 架构师 | 弹幕应用<span style="color: black;">研发</span>实战</a></p><strong style="color: blue;"><span style="color: black;">点击文末“阅读原文”,<span style="color: black;">认识</span><span style="color: black;">更加多</span>详情~</span></strong>




wrjc1hod 发表于 2024-10-7 05:23:49

你的见解独到,让我受益匪浅,非常感谢。

m5k1umn 发表于 2024-10-23 03:22:26

期待楼主的下一次分享!”

4zhvml8 发表于 2024-11-1 06:05:29

期待与你深入交流,共探知识的无穷魅力。
页: [1]
查看完整版本: PHP 遇见 Serverless,帮你处理这些痛点!