PHP 与apache 工作原理

When you sit down at your computer and pull up a web page using a browser such as Internet Explorer or Mozilla, you cause a little conversation to happen over the Internet between your computer and another computer. This conversation and how it makes a web page appear on your screen is illustrated in Figure 1-1.


 

Figure 1-1. Client and server communication without PHP


Here's what's happening in the numbered steps of the diagram:

  1. You type www.example.com/catalog.html into the location bar of Internet Explorer.

  2. Internet Explorer sends a message over the Internet to the computer named www.example.com asking for the /catalog.html page.

  3. Apache, a program running on the www.example.com computer, gets the message and reads the catalog.html file from the disk drive.

  4. Apache sends the contents of the file back to your computer over the Internet as a response to Internet Explorer's request.

  5. Internet Explorer displays the page on the screen, following the instructions of the HTML tags in the page.

Every time a browser asks for http://www.example.com/catalog.html, the web server sends back the contents of the same catalog.html file. The only time the response from the web server changes is if someone edits the file on the server.

When PHP is involved, however, the server does more work for its half of the conversation. Figure 1-2 shows what happens when a web browser asks for a page that is generated by PHP.


 

Figure 1-2. Client and server communication with PHP


Here's what's happening in the numbered steps of the PHP-enabled conversation:

  1. You type www.example.com/catalog/yak.php into the location bar of Internet Explorer.

  2. Internet Explorer sends a message over the Internet to the computer named www.example.com asking for the /catalog/yak.php page.

  3. Apache, a program running on the www.example.com computer, gets the message and asks the PHP interpreter, another program running on the www.example.com computer, "What does /catalog/yak.php look like?"

  4. The PHP interpreter reads the file /usr/local/www/catalog/yak.php from the disk drive.

  5. The PHP interpreter runs the commands in yak.php, possibly exchanging data with a database program such as MySQL.

  6. The PHP interpreter takes the yak.php program output and sends it back to Apache as an answer to "What does /catalog/yak.php look like?"

  7. Apache sends the page contents it got from the PHP interpreter back to your computer over the Internet in response to Internet Explorer's request.

  8. Internet Explorer displays the page on the screen, following the instructions of the HTML tags in the page.

"PHP" is a programming language. Something in the web server reads your PHP programs, which are instructions written in this programming language, and figures out what to do. The "PHP interpreter" follows your instructions. Programmers often say "PHP" when they mean either the programming language or the interpreter. In this book, I mean the language when I say "PHP." When I say "PHP interpreter," I mean the thing that follows the commands in the PHP programs you write and that generates web pages.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值