Home > Backend Development > PHP Tutorial > Installation of PHPlet under Windows_PHP Tutorial

Installation of PHPlet under Windows_PHP Tutorial

WBOY
Release: 2016-07-21 16:09:06
Original
944 people have browsed it

PHPlet是什么?
很简单,它是一个使用PHP编写的Web服务器,可以替代我们常用的Apache或IIS。
为什么要介绍PHPlet?
因为它是PHPer们学习Web服务器原理的捷径。
因为它的程序结构很好,类似Java的面向对象编程,有很好的参考价值。
因为我认为PHP5和PHPlet相继发布稳定版本后,PHP5+PHPlet+SQLite(PPS)将是小型应用、程序演示的另外一种选择。
现在大部分的小型应用或者程序演示都是把Apache+PHP+MySQL(APM结构)做成exe或rpm安装包,它的容量在8M-45M左右。如果使用了PPS结构整个系统将会缩减到2-3M之内(SQLite是嵌入式数据库),而且省去了对Apache和MySQL的依赖。
PHPlet的运行方式?
PHPlet使用php_socktes.dll实现端口侦听。
PHPlet是常驻内存的,可以使用srvany.exe将它作为NT的服务运行。
PHPlet的多进程功能只能运行在Linux、FreeBSD、*unx系统等系统下,这是因为PHP的“进程控制函数库”不支持Win32平台。

好了,废话不多说,马上进入我们的PHPlet之旅。

一.资源下载:
l          PHP
ZIP-Format: http://cn.php.net/download/
TGZ-Format: http://cn.php.net/download/
要下载最新的稳定版本,这样会得到更好的性能和稳定性。我用的是PHP4.3.6,写这篇文档时PHP5还在测试阶段。
要下载ZIP包而不是安装包,因为安装版(其实是简化版)中没有我们需要的DLL动态链接库。

l           PHPlet
ZIP-Format: http://phplet.sourceforge.net/
TGZ-Format: http://phplet.sourceforge.net/
要下载最新的稳定版本,这样会得到更好的性能和稳定性。我用的是PHPlet0.0.7,写这篇文档时还没有稳定版本。

二.安装:
l          PHP

解压缩到D:\PHP4:
如果你是初学者最好释放到我说的目录,否则后面会带来一些麻烦。
创建cli_php.exe:
将D:\PHP4\cli\php.exe复制到D:\PHP4\cli_php.exe。
它是PHPlet的启动程序,复制到D:\PHP4是为了能跟php.exe共享php.ini。
PEAR的安装:
PHPlet扩展了Pear的类库,那么我们先来安装Pear。
前提是你的电脑处于连线状态,因为安装程序需要下载一部分组件(还没研究如何不下载)。
另外你的身份必须是Administrator,因为安装程序中会在Windows目录下创建pear.ini。
一切准备就绪后运行D:\PHP4\go-pear.bat开始安装。

第一步. 直接按回车(也可以CTRL+C退出:D):
Welcome to go-pear!

Go-pear will install the 'pear' command and all the files needed by
it.  This command is your tool for PEAR installation and maintenance.

Go-pear also lets you download and install the PEAR packages bundled
with PHP: DB, Net_Socket, Net_SMTP, Mail, XML_Parser, PHPUnit-0.6.2.

If you wish to abort, press Control-C now, or press Enter to continue:

 
第二步. 输入Pear下载地址:
用来指定Pear组件的下载地址和端口,可以直接按回车。
HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none::

 
第三步. PHP路径设置:
一共7项,输入相应的序号就可以修改,输入"all"是修改全部,一般情况下只需要修改第7项。
选择第7项后会弹出一个windows的选择目录对话框,选择D:\PHP4。
Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation prefix                           : D:\PHP4
 2. Binaries directory                          : $prefix
 3. PHP code directory ($php_dir)   : $prefix\pear
 4. Documentation base directory   : $php_dir\docs
 5. Data base directory                      : $php_dir\data
 6. Tests base directory                    : $php_dir\tests
 7. php.exe path                                  :

1-7, 'all' or Enter to continue:


4. Confirm:
Confirm whether some components are installed. Enter "Y" here because PHPlet is using them.
The following PEAR packages are bundled with PHP: DB, Net_Socket, Net_SMTP,
Mail, XML_Parser, PHPUnit-0.6.2.
Would you like to install these as well? [Y/n] :


5. Install or download components:
Please wait a few minutes, the installer will automatically download the components and install them.
If there is an error in downloading "PHPUnit-0.6.2", an error will be reported. At this time, you need to check your network connection. (As long as the network is normal, there will generally be no problem. You can visit http://pear.php.net to try)
Loading zlib: ok
Using local package: PEAR..... ...ok
Using local package: Archive_Tar......ok
Using local package: Console_Getopt....ok
Using local package: XML_RPC.......... ok
Bootstrapping: PEAR.............(local) ok
Bootstrapping: Archive_Tar............(local) ) ok
Bootstrapping: Console_Getopt............(local) ok
Using local package: DB.............ok
Using local package: Net_Socket.....ok
Using local package: Net_SMTP.....ok
Using local package: Mail..... ok
Using local package: XML_Parser....ok
Downloading package: PHPUnit-0.6.2....

Okay, Pear has been installed here.
Modify php.ini:
Rename D:PHP4php.ini-dist to php.ini, and then open it.

Found:
; Windows: "path1;path2"
;include_path = ".;c:phpincludes"
Changed to:
; Windows: "path1;path2"
include_path = ".;D:PHP4includes;D:PHP4PEAR"

Find: extension_dir = "./" Change to: extension_dir = "D:PHP4extensions"

Find:;extension= php_sockets.dll Change to: extension=php_sockets.dll


l PHPlet

Unzip to D:PHP4PHPlet:
If you are a beginner, it is best to release it to what I said directory, otherwise it will cause some trouble later.
Change the configuration file:
Open D:PHP4PHPletconfigphplet.conf

"WEB_ROOT" is modified to: "D:\PHP4\PHPlet\www"
"HTTP_HOSTNAME" is modified to: "localhost"
"HTTP_HOSTPORT" is modified to: "8080"
"HTTP_SERVER_MODE" is modified to: "sequential"
"HTTP_SERVER_DEBUG" is modified to: "false"
"PHP_EXECUTABLE" is modified to: "D:\PHP4 \php.exe"
"CLASSLOADER_SINTAX_CHECK" modified to: "false"
Change startup file:
Open D:PHP4PHPletbinphpletstart.bat

link: http://www.knowsky.com

"PHP_EXE" is modified to: D:PHP4cli_php.exe
3. Start! Start the server!
Go to D:PHP4PHPletbin and double-click phpletstart.bat to start the service.
Okay, open the browser and enter http://localhost:8080/phplet/HelloWorld to see the effect.
4. Performance test
It was found that as long as it is run once, no matter how much modification (or even deletion) is made to HelloWorld.php, it will not change the result of the second refresh (it is very similar to Java Servlet, right?), unless it is restarted Start the server. So I feel that its performance must be great. As expected, please see my test results:
Server A (PHP4+PHPlet), especially a terrible AMD K6-2 400 + 128M.
Client B (Windows2003+IE6), P42.6G + 500M
Client B enters the URL http://192.168.0.15:8080/PHPler/HelloWord.php and then holds down F5 for 1 minute, Server A The CPU usage is constantly at 60%. If it is Apache2+PHP4 (CGI mode), refreshing at this frequency will continue to be 100%. After a long time, the virtual memory may be used up!

Of course, the above is only a one-sided test. As a WEB service, the more important thing is stability. Due to time constraints, there is no time for more detailed testing. We can discuss it together after doing more tests.
5. Notes
1. As mentioned above, PHPlet programming is somewhat similar to Java Servlet. As long as it is run once, no matter how much changes (or even deletions) are made to .php, the result of the second refresh will not be changed.
2. It is best to set the HTTP_HOSTNAME (host name) of PHPlet to your IP instead of localhost, otherwise other hosts cannot access through your IP.
3. Do not use exit in the program, use return to exit, otherwise the PHPlet server will be shut down.
4. You should use the $response->write() method to input a string, because print or echo will output the string to the terminal.
5. PHPlet does not support virtual directories and virtual host functions.
6. Conclusion
I have not been exposed to Pear, PHPlet and Socktes function libraries before writing this article, so some terms may not be accurate enough. Corrections are welcome!
Friends who are familiar with PHPlet and other web servers hope to communicate with each other. If you have any questions, you can also write to me.

Contribute your meager strength to China’s PHP cause ---- Mao Song

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314583.htmlTechArticleWhat is PHPlet? Very simply, it is a web server written in PHP, which can replace our commonly used Apache or IIS. Why introduce PHPlet? Because it is for PHPers to learn web services...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template