u1jodi1q 发表于 2024-10-5 03:54:08

PHP 的运行方式有哪些?


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP本质上的运行方式<span style="color: black;">能够</span>分为两种:</p>基于命令行的基于PHP-FPM的<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">但<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>工作。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">测试<span style="color: black;">研发</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP内置了一个HTTP 的server。这<span style="color: black;">寓意</span>着,<span style="color: black;">非常多</span>时候,<span style="color: black;">咱们</span>不需要nginx、apache、php-fpm、配置站点等等繁琐的操作,直接就<span style="color: black;">能够</span>运行php的代码。</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>简单的一行命令:</p>php -S localhost:8000<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">此时当前目录下的各类html、静态文件、php代码就都能正常返回运行了。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">能够</span>定义一个路由文件router.php,设置<span style="color: black;">有些</span>规则:</p>&lt;?php
    // router.php
    if (preg_match(/\.(?:png|jpg|jpeg|gif)$/, $_SERVER["REQUEST_URI"]))
    return false; // 直接返回请求的文件
    else {
    echo "&lt;p&gt;Welcome to PHP&lt;/p&gt;";
    }<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>,否则返回一段html代码。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP自5.1的版本起,内置封装了PHP的内置服务器。只要再TP项目下运行命令:</p>php think run<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这般</span>这个框架就运行起来了,不需要配置Nginx、Apache、静态规则、站点的目录、域名host等等等,一行命令就<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>的时候,只把对应版本的PHP配置到环境变量里,其他的各类nginx等软件一律<span style="color: black;">不消</span>,<span style="color: black;">研发</span>非常方便。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/9ad003f39570438b8b680c06f663a812~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728295205&amp;x-signature=sJ9%2FmFz%2BQI3UUkOQgOquoS7RVNg%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <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>临时演示来用。PHP的内置服务器<span style="color: black;">不可</span>处理并发请求,所有的请求(<span style="color: black;">包含</span>css、js等文件)都只能一个一个的处理。<span style="color: black;">然则</span>做<span style="color: black;">研发</span>是完全足够的。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">传统的<span style="color: black;">安排</span>方式</h1>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/0b827f50d5624370a00d141d076be92e~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728295205&amp;x-signature=11fS8HqbZJ8iFwCt3hQ3O%2FjuS7s%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP的FPM是黑科技,这是真的,稳如老狗,怎么折腾都不会出问题,<span style="color: black;">每一个</span>请求之间隔离得清清楚,互不影响,这一点当你在用Java、Node、Go等Http框架下<span style="color: black;">研发</span>时就会体会到了。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">通常</span>而言,PHP-fpm和nginx<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>要开启opcache、<span style="color: black;">必定</span>要开启opcache、<span style="color: black;">必定</span>要开启opcache。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">开启opcache之后,直接无脑的<span style="color: black;">得到</span>巨大的性能提醒。如今的PHP项目,PHP代码<span style="color: black;">非常多</span>,<span style="color: black;">由于</span><span style="color: black;">运用</span>composer依赖等,随随便便几百个文件<span style="color: black;">或</span>小一千个文件是常态,有些重量级框架动辄几十M<span style="color: black;">乃至</span>上百M的代码,<span style="color: black;">倘若</span>不开启是opcache,老狗<span style="color: black;">亦</span>会难受。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">基于TCP/UDP的网络编程</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">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>基于TCP和UDP协议进行各类业务的<span style="color: black;">研发</span>,<span style="color: black;">例如</span>例如即时通讯类、物联网、游戏、服务治理、其它服务器<span style="color: black;">或</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><span style="color: black;">亦</span>都很热门,<span style="color: black;">这儿</span><span style="color: black;">再也不</span><span style="color: black;">太多</span>介绍:</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Workerman</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">基于官方扩展<span style="color: black;">运用</span>纯PHP<span style="color: black;">研发</span>的网络编程和进程管理库,内置进程<span style="color: black;">保护</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Swoole</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">纯C<span style="color: black;">研发</span>的PHP扩展库,高性能、协程。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ReactPHP</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">像Node<span style="color: black;">同样</span>的事件驱动框架。国外热门主流,衍生了非常多的有趣的项目,<span style="color: black;">例如</span>有人用它实现了一套Redis server。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Swow</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运用</span>C和PHP实现的一套框架,专注于IO。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">GatewayWorker</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">基于Workerman<span style="color: black;">研发</span>的长连接框架,<span style="color: black;">研发</span>体验极佳,自动抹平协议沟通,实现TCP、websocket等<span style="color: black;">各样</span>协议的对接,支持分布式<span style="color: black;">安排</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><span style="color: black;">能够</span>留言。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Revolt</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">将来</span>事实上的PHP异步、协程标准。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">基于TCP和Linux事件机制的高性能HTTP框架</h1>
    <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>基于上面介绍的框架实现的专门用于HTTP<span style="color: black;">研发</span>的框架。刚才介绍的框架基本是能够实现TCP、UDP网络编程的,本小节<span style="color: black;">重点</span>介绍<span style="color: black;">研发</span>HTTP的部分,大部分<span style="color: black;">亦</span>是基于上面这些框架实现的。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Webman</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基于Workerman的高性能HTTP框架,简单易用,基本的MVC体验。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Swoole系</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基于swoole扩展实现的高性能HTTP框架,<span style="color: black;">例如</span>easyswoole,Hyperf等等。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">PHP-PM</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基于ReactPHP实现的PHP进程管理,<span style="color: black;">能够</span>无缝与标准的请求、响应框架集成驱动。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">RoadRunner</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">GO语言编写的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>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">基于命令行的业务</h1>
    <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>ThinkPHP、laravel等框架<span style="color: black;">供给</span>的自定义命令去实现了。但不<span style="color: black;">表率</span>PHP<span style="color: black;">无</span>这方面的成熟的框架。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">极简的命令行框架</h1>
    <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>的输出.</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/f37a3aa84b2142a08cb3887e19266dd8~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728295205&amp;x-signature=sjEViXWAe1yGC27mzKxLVJ5Ido4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">一个PHP的实时交互<span style="color: black;">掌控</span>台</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PsySH是一个实时运行的交互的命令行项目。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">一个PHP功能健全的命令行功能操作库</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">一个事实上的PHP标准的命令行框架。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">SeverLess服务</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">可能有些PHP没接触过这个概念,大体的意思是,<span style="color: black;">不消</span>自己<span style="color: black;">安排</span>运维服务器了,只要把代码上传到severless的服务上<span style="color: black;">就可</span>,按计算扣积分。基本都是各大服务器厂家<span style="color: black;">供给</span>的服务。其中laravel对其有很好的支持,其他<span style="color: black;">亦</span>有<span style="color: black;">有些</span>框架能够很容易的实现。<span style="color: black;">例如</span>Bref,简单且可扩展的服务框架。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">总结</h1>
    <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>的业务场景。</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>意思的项目,<span style="color: black;">例如</span>:</p>KPHP,把PHP编译成C++代码。peachpie,把PHP便以为.NET平台程序PHP-JS,集成Node引擎的PHP扩展PHP-CPP,<span style="color: black;">运用</span>C++<span style="color: black;">研发</span>PHP扩展,代码很容易上手<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些项目在我的另一篇<span style="color: black;">文案</span>有介绍:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">《PHP的几个有趣的打开方式:从基本到变态》https://phpreturn.com/index/a623dc0357dead.html</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">其他</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">近期</span>又出了几个PHP代码“编译”功能的项目,<span style="color: black;">重点</span>的目并不是性能,而是源码<span style="color: black;">守护</span>,ulthon_admin的有个分支正在做这件事,还<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>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">原文标题:PHP 的运行方式有<span style="color: black;">那些</span>?</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">原文<span style="color: black;">位置</span>:https://phpreturn.com/index/a640bdfa37386b.html</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">原文平台:PHP武器库</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">版权声明:本文由phpreturn.com(PHP武器库官网)原创和首发,所有权利归phpreturn(PHP武器库)所有,本站<span style="color: black;">准许</span>任何形式的转载/引用<span style="color: black;">文案</span>,但必须<span style="color: black;">同期</span>注明出处。</p>




nykek5i 发表于 2024-10-30 03:01:00

“板凳”(第三个回帖的人)‌

b1gc8v 发表于 2024-11-2 04:33:46

楼主果然英明!不得不赞美你一下!
页: [1]
查看完整版本: PHP 的运行方式有哪些?