Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Python web test

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.

HowTo

Put the files .htaccess, python_test.py and/or python_test_mini.py into your htdocs directory. Change .htaccess for your needs.

SCGI

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>

logging

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

Which handler?

How to find out what the handler is running script?

mod_wsgi

if __name__.startswith('_mod_wsgi_'):
    # we running with mod_wsgi

or:

if sys.argv[0] == "mod_wsgi":
    # we running with mod_wsgi

see also: https://code.google.com/p/modwsgi/wiki/TipsAndTricks#Determining_If_Running_Under_mod_wsgi

mod_python

if __name__.startswith('_mp_'):
    # we running with mod_python

or:

if sys.argv[0] == "mod_python":
    # we running with mod_python

SCGI

This have i seen on the internet, but not tested:

if sys.argv[0] == "scgi-wsgi":
    # we running with SCGI

(See SCGI section above.)

fastCGI, fcgid or CGI ?

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 module

Does anyone have a better idea?


copyleft 2011 by Jens Diemer

license: GNU GPL v3 or above