[ACCEPTED]-What's difference between a simple webserver and Apache server?-webserver
Or in other words, if i want to use python 59 to implement a server which can be put into 58 use of business, what also should i do?
There 57 are already python-based web servers, such 56 as CherryPy (which I think is intended to 55 be a web server solution on the same stack 54 level as Apache; it is more python-based 53 though, and Apache has been around a lot 52 longer).
If you wish to write a lightweight 51 extremely simple webserver from scratch, there 50 is probably nothing wrong with using BaseHTTPServer, other 49 than perhaps a few outstanding design issues 48 (I hear race conditions might permanently 47 clog a socket until a thread dies).
Though 46 I would not recommend it (alone) for business, some 45 of the big boys use BaseHTTPServer with 44 a bit of extra machinery: http://www.cherrypy.org/browser/trunk/cherrypy/_cphttpserver.py?rev=583
To elaborate, Apache 43 is the industry standard. It has a plethora 42 of configuration options, a security team, vulnerability 41 mailing lists I think, etc. It supports 40 modules (e.g. mod_python). Python-based 39 web servers also support python-based modules 38 (maybe they might allow you access to non-python 37 things) via something called a WSGI stack; a 36 WSGI application can run on any python-based 35 web server (and Apache too, which also has 34 a modwsgi); I think they are narrower in 33 scope than Apache modules.
Apache module 32 examples: http://httpd.apache.org/docs/2.0/mod/
WSGI examples (not a valid comparison): http://wsgi.org/wsgi/Middleware_and_Utilities
I 31 might code my own webserver if I'm doing 30 something extremely lightweight, or if I 29 needed massive control over webserver internals 28 that the module interfaces could not provide, or 27 if I was doing a personal project. I would 26 not code my own server for a business unless 25 I had significant experience with how real-world 24 web servers worked. This is especially important 23 from a security vulnerability point-of-view.
For 22 example, I once wrote a web-based music 21 player. I used a BaseHTTPServer to serve 20 music out of a sandbox I had written to 19 ensure that people couldn't access arbitrary 18 files. Threading was a nightmare. (I recall 17 a bug where you needed to pass special arguments 16 to Popen since threading caused an implicit 15 fork which would cause hangs on dangling 14 file descriptors.) There were other various 13 issues. The code needed to be refactored 12 a lot. It can be very worthwhile for a personal 11 project, but is a significant undertaking 10 and not worth it for a business that just 9 needs a website.
I know two startups who 8 have been content using Pylons (using Paste) or 7 Turbogears (using CherryPy) in the past, if 6 you're looking for a lightweight python 5 web server stack. Their default template 4 systems are lacking though. The choice between 3 Apache and a leaner more python-based web 2 server may also depend on the skillset of 1 your co-developers.
Apache is written in C and designed to be 4 scalable while BaseHTTPServer is meant for 3 local/testing/debugging environments.
So 2 you shouldn't use BaseHTTPServer for any 1 production sites.
Apache web server knows and supports the 8 entire HTTP protocol, so it can deal with 7 all the complications having to do with 6 headers, keeping connections open, caching 5 content, all the different HTTP response 4 codes and their proper treatment, etc.
You'd 3 have to understand the entire HTTP protocol 2 and express it in code to go beyond your 1 simple HTTP server.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.