In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The main content of this article is "introduction to the use of PHP5.4 built-in Web server". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "introduction to the usage of PHP5.4 built-in Web server".
PHP is a scripting language that requires a PHP interpreter to analyze and run PHP files. When PHP is used as a CGI service Web request, it needs to be embedded in some kind of Web server, most commonly integrated into Apache or IIS, that is, before using PHP, you need to install Apache or IIS and correctly configure their parameters for integration with PHP. Although this configuration is standardized and well documented, we often encounter problems installing Apache and PHP integration, and sometimes we just want to test a simple PHP feature without installing and starting Apache services for it.
However, according to official documents, this built-in Web server is only for development testing and is not recommended in a production environment. Because this server accepts processing requests sequentially, it cannot be processed concurrently.
This built-in web server is very easy to use, you only need to execute the following command:
$php-S localhost:8000
And then you can access it. After this startup, the default web service directory is the current directory where the command is executed. If you do not want to use the current directory, you need to use the-t parameter to specify it.
Example # 1 start the Web server
$cd ~ / public_html $php-S localhost:8000
Terminal output information:
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
When the http://localhost:8000/ and http://localhost:8000/myscript.html addresses are requested, the terminal outputs information similar to the following:
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 Request read 39144 GET / favicon.ico-Request read [Thu Jul 21 10:48:50 2011]:: 1 favicon.ico 39146 GET /-Request read [Thu Jul 21 10:48:50 2011]:: 1 Thu Jul 39147 GET / favicon.ico-Request read [Thu Jul 21 10:48:52 2011]:: 1favicon.ico 39148 GET / myscript.html-Request read [Thu Jul 21 10:48:52 2011]:: 1 39149 GET / favicon.ico-Request read
Example # 2 specify the root directory of the document when you start the web server
$cd ~ / public_html $php-S localhost:8000-t foo/
Terminal display information:
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
If you append a php script file to the startup command line, it will be treated as a "router" script. This script will be responsible for all HTTP requests. If the script returns FALSE when the script is executed, the requested resources will return normally. If it is not FALSE, what will be displayed in the browser will be the content generated by this script.
Example # 3 uses a router script
In this example, a request for a picture returns the corresponding picture, but a request for a HTML file displays "Welcome to PHP":
$php-S localhost:8000 router.php
Example # 4 determines whether a built-in web server is being used
Adjust the different behavior of the same PHP router script in the built-in Web server and in the production server through program judgment:
$php-S localhost:8000 router.php
This built-in web server recognizes standard MIME type resources with extensions such as .css, .gif, .htm, .html, .jpe, .jpeg, .jpg, .js, .png, .svg, and and .txt. Extension to support for .htm and .svg was only supported after PHP 5.4.4.
Example # 5 deals with unsupported file types
If you want this Web server to properly handle unsupported MIME file types, do this:
$php-S localhost:8000 router.php
If you want to access the built-in web server remotely, your startup command needs to be changed to the following:
Example # 6 remotely access this built-in Web server
$php-S 0.0.0.0purl 8000
So you can access the built-in web server remotely through port 8000.
At this point, I believe you have a deeper understanding of the "introduction to the use of PHP5.4 built-in Web server". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.