����Web Server

PHP 5.4.0�� CLI SAPI �ṩ��һ�����õ�Web��������

������õ�Web��������Ҫ���ڱ��ؿ���ʹ�ã������������ϲ�Ʒ������

URI����ᱻ���͵�PHP���ڵĵĹ���Ŀ¼��Working Directory�����д���������ʹ����-t�������Զ��岻ͬ��Ŀ¼��

�������δָ��ִ���ĸ�PHP�ļ�����Ĭ��ִ��Ŀ¼�ڵ�index.php ���� index.html������������ļ��������ڣ��������᷵��404����

�������������������Web Serverʱ�����ָ����һ��PHP�ļ���������ļ�����Ϊһ��"·��"�ű�����ζ��ÿ�����󶼻���ִ������ű����������ű����� FALSE ����ôֱ�ӷ���������ļ�����������̬�ļ������κδ�����������������ص��������

Example #1 ����Web������

$ cd ~/public_html
$ php -S localhost:8000

�ն˴��ڻ���ʾ:

PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press Ctrl-C to quit

���ŷ���http://localhost:8000/��http://localhost:8000/myscript.html�����ڻ���ʾ��

PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press Ctrl-C to quit.
[Thu Jul 21 10:48:48 2011] ::1:39144 GET /favicon.ico - Request read
[Thu Jul 21 10:48:50 2011] ::1:39146 GET / - Request read
[Thu Jul 21 10:48:50 2011] ::1:39147 GET /favicon.ico - Request read
[Thu Jul 21 10:48:52 2011] ::1:39148 GET /myscript.html - Request read
[Thu Jul 21 10:48:52 2011] ::1:39149 GET /favicon.ico - Request read

Example #2 ����ʱָ����Ŀ¼

$ cd ~/public_html
$ php -S localhost:8000 -t foo/

�ն˴�����ʾ��

PHP 5.4.0 Development Server started at Thu Jul 21 10:50:26 2011
Listening on localhost:8000
Document root is /home/me/public_html/foo
Press Ctrl-C to quit

Example #3 ʹ��·�ɣ�Router���ű�

����ͼƬֱ����ʾͼƬ������HTML����ʾ"Welcome to PHP"

<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/'$_SERVER["REQUEST_URI"]))
    return 
false;    // ֱ�ӷ���������ļ�
else { 
    echo 
"<p>Welcome to PHP</p>";
}
?>
$ php -S localhost:8000 router.php

ִ��֮���ն���ʾ��

PHP 5.4.0 Development Server started at Thu Jul 21 10:53:19 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press Ctrl-C to quit.
[Thu Jul 21 10:53:45 2011] ::1:55801 GET /mylogo.jpg - Request read
[Thu Jul 21 10:53:52 2011] ::1:55803 GET /abc.html - Request read
[Thu Jul 21 10:53:52 2011] ::1:55804 GET /favicon.ico - Request read