題主以爲:跟其它脚本语言比如 nodejs, python, ruby 不一样,PHP 必须依赖服务器存在,为什么它不把整个 http 的生命周期都放到 php 内部去管理,而非要依赖一个 web 服务器提供接口呢?
回复内容:
題主以爲:跟其它脚本语言比如 nodejs, python, ruby 不一样,PHP 必须依赖服务器存在,为什么它不把整个 http 的生命周期都放到 php 内部去管理,而非要依赖一个 web 服务器提供接口呢?
纯PHP实现的WebServer也有啊,例如workerman框架就自带了一个WebServer,整个http生命周期都是由PHP自己管理的,不依赖nginx apache php-fpm,并且数据库链接资源、全局对象等都可以永久保存并复用,性能确实提高不少。
另外PHP也自带了一个web服务器, php -S 启动,不过无法用于生产环境。
命令行下也可以直接运行 php file.php 运行脚本,也不依赖web服务器。
只是像PHP的web开发nginx+php-fpm 或者apache+php 这样的架构比较成熟了,所以大家都一直这样用,感觉PHP必须依赖Web服务器一样。当然如果要用PHP开发非http协议的应用,例如TCP长链接,还真得脱离现有的web架构,就得使用PHP的socket服务器框架。
PHP可以不依赖php-fpm、apache、nginx这些容器就可以独立运行。
传统PHP开发都是基于Web的,基本上都是HTTP协议,HTTP协议的解析处理都由WebServer独自承担了,所以开发者不会关心协议方面的事情。然而当我们需要基于非HTTP协议开发时,传统WebServer无法满足我们的需求,这时需要开发者实现协议解析部分。
PHP解释器现在内置了一个服务器,可以用 php -S 启动,虽说目前只能用于开发测试用。。
没有依赖呀,有命令行下php a.php
就能执行一个php文件
在Web服务器中,php和python等脚本语言也没有本质区别
都是通过网关接口调用并返回的
1.因为当前的技术已经成熟了,所以没有必要去开发一个服务器去。
2.php语言中没有提供api来创建一个web server,php语言更专注于web内容处理。现行的php引擎在一次http请求结束后,就回收掉所有变量信息,说白了开发web过程中php不常驻内存。
你这命题就不对吧
以前的php clisapi 这个工具感觉应该是不是太被重视,以至很多人都不清楚甚至不知道,所以以为运行php代码必须借助浏览器离开浏览器php就不能运行,但现在的从php5.3开始更新这么频繁发生不少的变化,再有php一开始就与apache有了很好的结合很好的很方便处理了http交接转换,使人可以在php本身层面对处理request,response可以太方便的进行处理,不像python等语言要开发web要自己去实现与http交换数据的接口需要自己实现开发web而去开发一些web框架,php的框架都是应用框架。如果没有了mod_php php-fcgi php-fpm 这些东西,那想用php开发web 就跟python等语言一样了自己用php去开发实现能与http交接数据的web框架了。对一开始学习php的都是直笨主题开发、部署web是多么的方便与简单,很少会有提到背后已经实现了的技术知识,所以php才会让人感觉这么简单这么易学才会有这么多人用它。所以一些人才会忽略php是不是没有什么能脱离浏览器脱离web服务器可以单独运行的能力。
PHP那么火,就有一定的原因:他可以在各种环境下被支持,如果本身有了http,势必会限制他的发展。
php运行不是说一定要依赖容器,因为nginx/apache+php已经非常成熟了,性能又够用,web开发大家就都直接用这些容器了,稳定可靠,文档有多。
虽然PHP有ARC和GC,但还是存在内存泄露的。
用PHP扩展可以实现简单的WEB Server。比如这个用HttpEvent扩展实现的HTTP Server (http://php.net/manual/zh/eventhttp.construct.php)。
不过你可以测试一下,PHP官方提供的代码是存在内存泄漏的,经过十几万个请求后内存就跑满了

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
