search
HomeBackend DevelopmentPHP TutorialPHPlet在Windows下的安装_PHP

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:PHP4cliphp.exe复制到D:PHP4cli_php.exe。
它是PHPlet的启动程序,复制到D:PHP4是为了能跟php.exe共享php.ini。
PEAR的安装:
PHPlet扩展了Pear的类库,那么我们先来安装Pear。
前提是你的电脑处于连线状态,因为安装程序需要下载一部分组件(还没研究如何不下载)。
另外你的身份必须是Administrator,因为安装程序中会在Windows目录下创建pear.ini。
一切准备就绪后运行D:PHP4go-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) : $prefixpear
4. Documentation base directory : $php_dirdocs
5. Data base directory : $php_dirdata
6. Tests base directory : $php_dir ests
7. php.exe path :

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


4.确认:
确认一些组件是否安装,这里要输入"Y",因为PHPlet正用到他们。
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.安装或下载组件:
接下来请稍等几分钟,安装程序会自动下载组件并安装。
如果"PHPUnit-0.6.2"下载出错将会报错,这时就要检查一下你的网络连接了。(只要网络正常一般不会有问题,你可以访问http://pear.php.net试试)
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....

好了,到这里Pear已经安装完毕。
修改php.ini:
将D:PHP4php.ini-dist改名为php.ini,然后打开。

找到:
; Windows: "path1;path2"
;include_path = ".;c:phpincludes"
改为:
; Windows: "path1;path2"
include_path = ".;D:PHP4includes;D:PHP4PEAR"

找到:extension_dir = "./" 改为:extension_dir = "D:PHP4extensions"

找到:;extension=php_sockets.dll 改为:extension=php_sockets.dll


l PHPlet

解压缩到D:PHP4PHPlet:
如果你是初学者最好释放到我说的目录,否则后面会带来一些麻烦。
更改配置文件:
打开D:PHP4PHPletconfigphplet.conf

"WEB_ROOT" 修改为:"D:\PHP4\PHPlet\www"
"HTTP_HOSTNAME" 修改为:"localhost"
"HTTP_HOSTPORT" 修改为:"8080"
"HTTP_SERVER_MODE" 修改为:"sequential"
"HTTP_SERVER_DEBUG" 修改为:"false"
"PHP_EXECUTABLE" 修改为:"D:\PHP4\php.exe"
"CLASSLOADER_SINTAX_CHECK" 修改为:"false"
更改启动文件:
打开D:PHP4PHPletinphpletstart.bat

link:http://www.csdn.com.cn

"PHP_EXE" 修改为:D:PHP4cli_php.exe
三.开始!启动服务器!
进入到D:PHP4PHPletin,双击phpletstart.bat启动服务。
好了,打开浏览器输入http://localhost:8080/phplet/HelloWorld看一下效果吧。
四.性能测试
发现只要运行一次,无论对HelloWorld.php做任何修改(甚至删除),也不会改变第二次刷新的结果(跟Java Servlet很像吧?),除非重新启动服务器。所以我感觉它的性能一定很棒,不出所料,请看我的测试结果:
服务器A(PHP4+PHPlet),特别选了台很烂的 AMD K6-2 400 + 128M。
客户机B(Windows2003+IE6),P42.6G + 500M
客户机B输入网址 http://192.168.0.15:8080/PHPler/HelloWord.php 然后按住F5持续1分钟,服务器A占用CPU一直持续在60%。如果是Apache2+PHP4(CGI模式)以这样的频率刷新将会持续100%,时间长后有可能会沾光虚拟内存!

当然了,上面只是片面的测试,做为WEB服务更主要的还是稳定,因为时间关系也没功夫更详细的测试。大家可以作更多测试后再一起讨论。
五.注意事项
1. 上面说过PHPlet编程有点类似Java Servlet,只要运行一次无论对.php作任何更改(甚至删除),也不会改变第二次刷新的结果。
2. PHPlet的HTTP_HOSTNAME(主机名)最好设置成你的IP而不是localhost,否则其它主机无法通过你的IP访问。
3. 程序中不要使用exit,要使用return退出,否则将会关闭PHPlet服务器。
4. 应该用$response->write()方法输入字符串,因为print或echo会将字符串输出到终端上。
5. PHPlet不支持虚拟目录和虚拟主机功能。
六.结束语
写这篇文章之前并没有接触过Pear、PHPlet和Socktes函数库,所以有些术语可能说得不够准确,欢迎指正!
对PHPlet和其他Web服务器熟悉的朋友希望能相互交流,如果你有任何问题也可以写信给我。

Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools