Detect web handler: mod_wsgi, fast_CGI, fcgid, mod_python or CGI and display many informations.
- python_test.py displays many informations.
- python_test_mini.py is smaller and displays less informations.
Put the files .htaccess, python_test.py and/or python_test_mini.py into your htdocs directory. Change .htaccess for your needs.
The test script can run a SCGI Server, too. It's use the flup packages for this. To start a SCGI Server on localhost:4000 run this:
./python_test.py scgi
or specify bidn address and port:
./python_test.py scgi 127.0.0.1 8888
Add SCGIMount to your VirtualHost config, e.g.:
<VirtualHost>
...
SCGIMount / 127.0.0.1:4000
...
</VirtualHost>The test script write some logs into a log file. The problem is, to find a place for this log file. Depending on the user that runs the process, we have different file write rights and we try to find a filepath in which we can write out log output.
We try to create a log file in these directories:
- same directory as test script
- tempfile.gettempdir()
- /tmp
- /tmp
How to find out what the handler is running script?
if __name__.startswith('_mod_wsgi_'):
# we running with mod_wsgior:
if sys.argv[0] == "mod_wsgi":
# we running with mod_wsgisee also: https://code.google.com/p/modwsgi/wiki/TipsAndTricks#Determining_If_Running_Under_mod_wsgi
if __name__.startswith('_mp_'):
# we running with mod_pythonor:
if sys.argv[0] == "mod_python":
# we running with mod_pythonThis have i seen on the internet, but not tested:
if sys.argv[0] == "scgi-wsgi":
# we running with SCGI(See SCGI section above.)
It seems to be difficult to keep them apart. The current solution looks like this:
if __name__ == "__main__":
if "CGI" in os.environ.get("GATEWAY_INTERFACE", ""):
# normal CGI
elif "PATH" in os.environ:
# New libapache2-mod-fcgid Apache module
else:
# Old libapache2-mod-fastcgi Apache moduleDoes anyone have a better idea?
copyleft 2011 by Jens Diemer
license: GNU GPL v3 or above