1、php的调用过程
浏览器请求一个php文件的流程
test.php
1 <html> 2 <head> 3 <meta http-equiv="content-type" content="text/html" charset="utf-8"> 4 </head> 5 <body> 6 <?php 7 $i = 1 + 2; 8 echo "结果是".$i; 9 ?> 10 </body> 11 </html>
1、浏览器(http://localhost/test.php)解析主机名;
2、向HOST文件(127.0.0.1 localhost)查询主机对应的IP;
3、如果查询不到,跳到外网DNS;
4、浏览器向Apache服务器发出http请求
GET http://127.0.0.1/test.php HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Accept: */*
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
5、Apache解析主机;
6、Apache解析站点/目录;
7、Apache解析资源(请求文件)名;
8、Apache请求文件(test.php);
9、test.php中<?php ……?>代码在服务器端执行,Apache返回结果给浏览器
HTTP/1.1 200 OK Date: Mon, 12 Dec 2016 12:23:55 GMT Server: Apache/2.4.23 (Win64) PHP/5.6.25 X-Powered-By: PHP/5.6.25 Content-Length: 137 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 <html> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> </head> <body> 结果是3
</body> </html>
10、浏览器显示返回结果。
时序图