thttpd web server源代码学习一

来源:互联网 发布:炫舞时代辅助源码 编辑:程序博客网 时间:2024/06/08 11:47

      thttpd是一个开放源代码,非常小巧的轻量级web server,其网站为:http://www.acme.com/software/thttpd/ 。

/*以下是摘录自其网站的有关thttpd web server的介绍

thttpd is a simple, small, portable, fast, and secure HTTP server.

Simple:
It handles only the minimum necessary to implement HTTP/1.1. Well, maybe a little more than the minimum.
Small:
See the comparison chart. It also has a very small run-time size, since it does not fork and is very careful about memory allocation.
Portable:
It compiles cleanly on most any Unix-like OS, specifically including FreeBSD, SunOS 4, Solaris 2, BSD/OS, Linux, OSF.
Fast:
In typical use it's about as fast as the best full-featured servers (Apache, NCSA, Netscape). Under extreme load it's much faster.
Secure:
It goes to great lengths to protect the web server machine against attacks and breakins from other sites.

It also has one extremely useful feature (URL-traffic-based throttling) that no other server currently has. Plus, it supports IPv6 out of the box, no patching required.

*/

从google上搜索了一下,相关文章不少,但大多数都是相同的。

声明:该文的网址:http://www.hzqbbc.com/blog/arch/2005/05/lighttpdthttpds.html ,该文只为学习。
Thanks To: 谢谢google.com ,谢谢该文的作者,

May 
222005
lighttpd,thttpd,shttpd 
- 轻量级webserver介绍
国内绝大部分的web server不是IIS就是Apache,而论市场占有率,我认为Apache是大赢家了,至少是占据了半壁江山。

但除了IIS
/Apache外,其实我们有很多选择,对于高负载/大并发的网站而言,高性能、轻量级的web server是一剂良药。最近手头一台Server 的负载太高,居然将swap吃光导致机器非常缓慢,后来一查,原来是Apache耗掉了几乎所有资源,当时apache进程已有9XX个了。

于是用轻量级的web server替换掉apache就进入了日程表。这里顺带介绍一下这些可选的对象:
lighttpd 
| thttpd | shttpd

lighttpd
官方主页:www.lighttpd.net
Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。

lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能,而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多功能都有相应的实现了,这点对于apache的用户是非常重要的,因为迁移到lighttpd就必须面对这些问题。

在google搜索了一下,简体中文介绍lighttpd的文章几乎没有,大多数都是台湾同胞的Big5内容。因此在接下来的时间里,想好好写一篇介绍lighttpd,以及简单的benchmark的文章。

实用起来lighttpd确实非常不错,上文提到的apache overload的问题,用lighttpd就完全解决了。apache主要的问题是密集并发下,不断的fork()和切换,以及较高(相对于lighttpd而言)的内存占用,使系统的资源几尽枯竭。而lighttpd采用了Multiplex技术,代码经过优化,体积非常小,资源占用很低,而且反应速度相当快。

利用apache的rewrite技术,将繁重的cgi
/fastcgi任务交给lighttpd来完成,充分利用两者的优点,现在那台服务器的负载下降了一个数量级,而且反应速度也提高了一个甚至是2个数量级!


thttpd

官方网站:http:
//www.acme.com/software/thttpd/
thttpd是一个非常小巧的轻量级web server,它非常非常简单,仅仅提供了HTTP/1.1和简单的CGI支持,在其官方网站上有一个与其他web server(如Apache, Zeus等)的对比图+Benchmark,可以参考参考。此外,thttpd 也类似于lighttpd,对于并发请求不使用fork()来派生子进程处理,而是采用多路复用(Multiplex)技术来实现。因此效能很好。

Thttpd支持多种平台,如FreeBSD, SunOS, Solaris, BSD, Linux, OSF等。对于小型web server而言,速度快似乎是一个代名词,通过官方站提供的Benchmark,可以这样认为:thttpd至少和主流的web server一样快,在高负载下更快,因为其资源占用小的缘故。

Thttpd还有一个较为引人注目的特点:基于URL的文件流量限制,这对于下载的流量控制而言是非常方便的。象Apache就必须使用插件实现,效率较thttpd低。

shttpd
官方网站:http:
//shttpd.sourceforge.net/ Shttpd是另一个轻量级的web server,具有比thttpd更丰富的功能特性,支持CGI, SSL, cookie, MD5认证, 还能嵌入(embedded)到现有的软件里。最有意思的是不需要配置文件! 
由于shttpd可以嵌入其他软件,因此可以非常容易的开发嵌入式系统的web server,官方网站上称shttpd如果使用uclibc/dielibc(libc的简化子集)则开销将非常非常低。以下是其特点:

Stand
-alone server, or embeddable into existing C/C++ program 
GET, POST, PUT, DELETE methods 
CGI 
SSL 
Digest (MD5) authorization 
Multiple (and user defineable) index files 
Directory listing 
Standard logging 
Cookies 
inetd mode 
User
-defineable mime types 
No configuration files 
No external dependencies

由于shttpd可以轻松嵌入其他程序里,因此shttpd是较为理想的web server开发原形,开发人员可以基于shttpd开发出自己的webserver!

 

声明:本文的网址:http://bbs.chinaunix.net/viewthread.php?tid=853053
Thanks To:谢谢google.com  谢谢chinaunix.net   谢谢该贴的作者。
 
前些时候把thttpd
+ssl+php 整合到一起了。正好CU上有人问如何整合thttpd+ssl, 现在把我整合的文件一起传上来,包中php_thttpd.c.1 就是改后的php_thttpd.c , 原来是php 5.0.4生成的一个连接。 由于每个人整合的php 版本不一样,所以未使用 diff, 直接打包了修改的几个文件。
整合过程就是写个ssl_api.c ssl_api.h 包含了ssl初始化,bind,read,write,readv writev 等实现, 替代thttpd 中的相应处理。
如果不需要php, 可以使用此方法整合ssl 其他版本的thttpd. 目前php 自己只支持 thttpd 
2.21b.
证书可以用openssl 生成,和 apache 等一样。网上有很多介绍证书生成方法。

查看更详细信息请看原贴:)
 

 

从网站上下载了2.25b版本的thttpd。文件不大,约有51个文件。其中.h  .c的文件有16个. main函数在thttpd.c中,分析见thttpd web server源代码学习二:)

原创粉丝点击