標籤:http str local log mil src 技術分享 text power
瀏覽器請求一個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.1Host: 127.0.0.1User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36Accept: */*Accept-Encoding: gzip, deflate, sdch, brAccept-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 OKDate: Mon, 12 Dec 2016 12:23:55 GMTServer: Apache/2.4.23 (Win64) PHP/5.6.25X-Powered-By: PHP/5.6.25Content-Length: 137Keep-Alive: timeout=5, max=100Connection: Keep-AliveContent-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、瀏覽器顯示返回結果。
時序圖
1、php的調用過程