> For the complete documentation index, see [llms.txt](https://phper.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://phper.shujuwajue.com/phpxuan-xiang-he-yun-xing-yuan-li/php-sapi.md).

# PHP SAPI

SAPI：Server Application Programming Interface服务端应用编程端口。他就是php与其他应用交互的接口，php脚本要执行有很多中方式，通过web服务器，或者直接在命令行行下，也可以嵌入其他程序中。SAPI提供了一个和外部通信的接口，常见的SAPI有：cgi、fast-cgi、cli、模块。

> php的运行模式就是PHP SAPI 的类别

更多详细的php内核研究,这里有一个专题 [PHP内核探索：一次请求的开始与结束](http://www.nowamagic.net/librarys/veda/detail/1286)

此文章所在专题列表如下：

1. [PHP内核探索：从SAPI接口开始](http://www.nowamagic.net/librarys/veda/detail/1285)
2. [PHP内核探索：一次请求的开始与结束](http://www.nowamagic.net/librarys/veda/detail/1286)
3. [PHP内核探索：一次请求生命周期](http://www.nowamagic.net/librarys/veda/detail/1287)
4. [PHP内核探索：单进程SAPI生命周期](http://www.nowamagic.net/librarys/veda/detail/1289)
5. [PHP内核探索：多进程/线程的SAPI生命周期](http://www.nowamagic.net/librarys/veda/detail/1290)
6. [PHP内核探索：Zend引擎](http://www.nowamagic.net/librarys/veda/detail/1291)
7. [PHP内核探索：再次探讨SAPI](http://www.nowamagic.net/librarys/veda/detail/1292)
8. [PHP内核探索：Apache模块介绍](http://www.nowamagic.net/librarys/veda/detail/1293)
9. [PHP内核探索：通过mod\_php5支持PHP](http://www.nowamagic.net/librarys/veda/detail/1299)
10. [PHP内核探索：Apache运行与钩子函数](http://www.nowamagic.net/librarys/veda/detail/1312)
11. [PHP内核探索：嵌入式PHP](http://www.nowamagic.net/librarys/veda/detail/1318)
12. [PHP内核探索：PHP的FastCGI](http://www.nowamagic.net/librarys/veda/detail/1321)
13. [PHP内核探索：如何执行PHP脚本](http://www.nowamagic.net/librarys/veda/detail/1322)
14. [PHP内核探索：PHP脚本的执行细节](http://www.nowamagic.net/librarys/veda/detail/1323)
15. [PHP内核探索：操作码OpCode](http://www.nowamagic.net/librarys/veda/detail/1324)
16. [PHP内核探索：PHP里的opcode](http://www.nowamagic.net/librarys/veda/detail/1325)
17. [PHP内核探索：解释器的执行过程](http://www.nowamagic.net/librarys/veda/detail/1332)
18. [PHP内核探索：变量概述](http://www.nowamagic.net/librarys/veda/detail/1326)
19. [PHP内核探索：变量存储与类型](http://www.nowamagic.net/librarys/veda/detail/1327)
20. [PHP内核探索：PHP中的哈希表](http://www.nowamagic.net/librarys/veda/detail/1344)
21. [PHP内核探索：理解Zend里的哈希表](http://www.nowamagic.net/librarys/veda/detail/1348)
22. [PHP内核探索：PHP哈希算法设计](http://www.nowamagic.net/librarys/veda/detail/1349)
23. [PHP内核探索：翻译一篇HashTables文章](http://www.nowamagic.net/librarys/veda/detail/1366)
24. [PHP内核探索：哈希碰撞攻击是什么？](http://www.nowamagic.net/librarys/veda/detail/1367)
25. [PHP内核探索：常量的实现](http://www.nowamagic.net/librarys/veda/detail/1368)
26. [PHP内核探索：变量的存储](http://www.nowamagic.net/librarys/veda/detail/1386)
27. [PHP内核探索：变量的类型](http://www.nowamagic.net/librarys/veda/detail/1387)
28. [PHP内核探索：变量的值操作](http://www.nowamagic.net/librarys/veda/detail/1388)
29. [PHP内核探索：变量的创建](http://www.nowamagic.net/librarys/veda/detail/1389)
30. [PHP内核探索：预定义变量](http://www.nowamagic.net/librarys/veda/detail/1390)
31. [PHP内核探索：变量的检索](http://www.nowamagic.net/librarys/veda/detail/1393)
32. [PHP内核探索：变量的类型转换](http://www.nowamagic.net/librarys/veda/detail/1394)
33. [PHP内核探索：弱类型变量的实现](http://www.nowamagic.net/librarys/veda/detail/1401)
34. [PHP内核探索：静态变量的实现](http://www.nowamagic.net/librarys/veda/detail/1402)
35. [PHP内核探索：变量类型提示](http://www.nowamagic.net/librarys/veda/detail/1409)
36. [PHP内核探索：变量的生命周期](http://www.nowamagic.net/librarys/veda/detail/1414)
37. [PHP内核探索：变量赋值与销毁](http://www.nowamagic.net/librarys/veda/detail/1415)
38. [PHP内核探索：变量作用域](http://www.nowamagic.net/librarys/veda/detail/1420)
39. [PHP内核探索：诡异的变量名](http://www.nowamagic.net/librarys/veda/detail/1421)
40. [PHP内核探索：变量的value和type存储](http://www.nowamagic.net/librarys/veda/detail/1423)
41. [PHP内核探索：全局变量Global](http://www.nowamagic.net/librarys/veda/detail/1424)
42. [PHP内核探索：变量类型的转换](http://www.nowamagic.net/librarys/veda/detail/1437)
43. [PHP内核探索：内存管理开篇](http://www.nowamagic.net/librarys/veda/detail/1438)
44. [PHP内核探索：Zend内存管理器](http://www.nowamagic.net/librarys/veda/detail/1439)
45. [PHP内核探索：PHP的内存管理](http://www.nowamagic.net/librarys/veda/detail/1440)
46. [PHP内核探索：内存的申请与销毁](http://www.nowamagic.net/librarys/veda/detail/1441)
47. [PHP内核探索：引用计数与写时复制](http://www.nowamagic.net/librarys/veda/detail/1442)
48. [PHP内核探索：PHP5.3的垃圾回收机制](http://www.nowamagic.net/librarys/veda/detail/1452)
49. [PHP内核探索：内存管理中的cache](http://www.nowamagic.net/librarys/veda/detail/1453)
50. [PHP内核探索：写时复制COW机制](http://www.nowamagic.net/librarys/veda/detail/1454)
51. [PHP内核探索：数组与链表](http://www.nowamagic.net/librarys/veda/detail/1455)
52. [PHP内核探索：使用哈希表API](http://www.nowamagic.net/librarys/veda/detail/1456)
53. [PHP内核探索：数组操作](http://www.nowamagic.net/librarys/veda/detail/1457)
54. [PHP内核探索：数组源码分析](http://www.nowamagic.net/librarys/veda/detail/1458)
55. [PHP内核探索：函数的分类](http://www.nowamagic.net/librarys/veda/detail/1462)
56. [PHP内核探索：函数的内部结构](http://www.nowamagic.net/librarys/veda/detail/1463)
57. [PHP内核探索：函数结构转换](http://www.nowamagic.net/librarys/veda/detail/1464)
58. [PHP内核探索：定义函数的过程](http://www.nowamagic.net/librarys/veda/detail/1465)
59. [PHP内核探索：函数的参数](http://www.nowamagic.net/librarys/veda/detail/1466)
60. [PHP内核探索：zend\_parse\_parameters函数](http://www.nowamagic.net/librarys/veda/detail/1467)
61. [PHP内核探索：函数返回值](http://www.nowamagic.net/librarys/veda/detail/1473)
62. [PHP内核探索：形参return value](http://www.nowamagic.net/librarys/veda/detail/1474)
63. [PHP内核探索：函数调用与执行](http://www.nowamagic.net/librarys/veda/detail/1475)
64. [PHP内核探索：引用与函数执行](http://www.nowamagic.net/librarys/veda/detail/1489)
65. [PHP内核探索：匿名函数及闭包](http://www.nowamagic.net/librarys/veda/detail/1490)
66. [PHP内核探索：面向对象开篇](http://www.nowamagic.net/librarys/veda/detail/1491)
67. [PHP内核探索：类的结构和实现](http://www.nowamagic.net/librarys/veda/detail/1492)
68. [PHP内核探索：类的成员变量](http://www.nowamagic.net/librarys/veda/detail/1499)
69. [PHP内核探索：类的成员方法](http://www.nowamagic.net/librarys/veda/detail/1500)
70. [PHP内核探索：类的原型zend\_class\_entry](http://www.nowamagic.net/librarys/veda/detail/1512)
71. [PHP内核探索：类的定义](http://www.nowamagic.net/librarys/veda/detail/1513)
72. [PHP内核探索：访问控制](http://www.nowamagic.net/librarys/veda/detail/1514)
73. [PHP内核探索：继承，多态与抽象类](http://www.nowamagic.net/librarys/veda/detail/1515)
74. [PHP内核探索：魔术函数与延迟绑定](http://www.nowamagic.net/librarys/veda/detail/1519)
75. [PHP内核探索：保留类与特殊类](http://www.nowamagic.net/librarys/veda/detail/1520)
76. [PHP内核探索：对象](http://www.nowamagic.net/librarys/veda/detail/1521)
77. [PHP内核探索：创建对象实例](http://www.nowamagic.net/librarys/veda/detail/1522)
78. [PHP内核探索：对象属性读写](http://www.nowamagic.net/librarys/veda/detail/1523)
79. [PHP内核探索：命名空间](http://www.nowamagic.net/librarys/veda/detail/1524)
80. [PHP内核探索：定义接口](http://www.nowamagic.net/librarys/veda/detail/1525)
81. [PHP内核探索：继承与实现接口](http://www.nowamagic.net/librarys/veda/detail/1526)
82. [PHP内核探索：资源resource类型](http://www.nowamagic.net/librarys/veda/detail/1533)
83. [PHP内核探索：Zend虚拟机](http://www.nowamagic.net/librarys/veda/detail/1540)
84. [PHP内核探索：虚拟机的词法解析](http://www.nowamagic.net/librarys/veda/detail/1541)
85. [PHP内核探索：虚拟机的语法分析](http://www.nowamagic.net/librarys/veda/detail/1542)
86. [PHP内核探索：中间代码opcode的执行](http://www.nowamagic.net/librarys/veda/detail/1543)
87. [PHP内核探索：代码的加密与解密](http://www.nowamagic.net/librarys/veda/detail/1544)
88. [PHP内核探索：zend\_execute的具体执行过程](http://www.nowamagic.net/librarys/veda/detail/1580)
89. [PHP内核探索：变量的引用与计数规则](http://www.nowamagic.net/librarys/veda/detail/1581)
90. [PHP内核探索：新垃圾回收机制说明](http://www.nowamagic.net/librarys/veda/detail/1582)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://phper.shujuwajue.com/phpxuan-xiang-he-yun-xing-yuan-li/php-sapi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
