Mod python

来自开放百科 - 灰狐
跳转到: 导航, 搜索
Wikipedia-35x35.png 您可以在Wikipedia上了解到此条目的英文信息 Mod python Thanks, Wikipedia.

Apache/Python Integration

mod_python是apache组织的一个项目,通过它,可以开发psp或cgi,mod_python功能强大,速度快,是非常优秀的web开发工具。

安装

Debian用户

#apt-get install libapache-mod-python-doc - An Apache module that embeds Python within the server
#apt-get install libapache-mod-python2.1 - An Apache module that embeds Python 2.1 within the server
#apt-get install libapache-mod-python2.2 - An Apache module that embeds Python 2.2 within the server
#apt-get install libapache-mod-python2.3 - An Apache module that embeds Python 2.3 within the server
#apt-get install libapache2-mod-python - An Apache module that embeds Python within the server
#apt-get install libapache2-mod-python-doc - An Apache module that embeds Python within the server
#apt-get install libapache2-mod-python2.2 - An Apache 2 module that embeds Python 2.2 within the server
#apt-get install libapache2-mod-python2.3 - An Apache 2 module that embeds Python 2.3 within the server

Windows用户,建议不要使用,问题很多

http://apache.justdn.org/httpd/modpython/win/3.3.1/mod_python-3.3.1.win32-py2.5-Apache2.2.exe
会生成 C:\apache-2.2.3\modules\mod_python.so 文件
<Directory "C:/myweb/python/"> 
   AddHandler mod_python .html
   PythonHandler mptest 
   PythonDebug On 
 </Directory>
  
mptest.py
from mod_python import apache
def handler(req):
    req.content_type = 'text/plain'
    req.write("Hello World!")
    return apache.OK
http://localhost/python/mptest.html :)

性能

mod_python 的一个最主要优点就是在性能上超越传统CGI。下面是一个非常粗略的测试。该测试是在一台运行Red Hat Linux 7.3的奔腾1.2G的机器上完成的。Ab 用来对4种脚本进行测试,所有的都是从标准cgi模块输入(因为这是一个典型Python cgi脚本开始的方式), 然后输出一个简单的单词"Hello!"。这个结果是基于10000次并发为1的请求。

Standard CGI:               23 requests/s
Mod_python cgihandler:     385 requests/s
Mod_python publisher:      476 requests/s
Mod_python handler:       1203 requests/s
分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱