HOW TO USE
QUICKSTART
- download libfcgi-simple-example.py and libcfgi.pyd from downloads page
- copy both files into the same directory on your local machine
- set up a web server with fastcgi pointing to localhost:9000. Don't know how? you can download nginx from here (pick latest windows binary under 'stable versions'), it's easy to set up. Use this nginx conf file.
- start nginx.exe
- start libfcgi-simple-example.py (note: you can't ctrl+c out of this file -- just close the console to shut it off)
- if you used my conf file, point your web browser to http://127.0.0.1/anything.py
- should work
EXPLANATION
libfcgi-simple-example.py is pretty easy to understand: It's only 21 lines long, most of which is explanatory print statements. Key things to note:
* call libfcgi.init_socket(port_number,backlog) before anything. not sure what backlog does, I use 10.
* libfcgi.fcgi_request() creates an fcgi_request object.
* call accept on the request object to wait for a connection
* request object has dictionary named env with environment variables passed by web server. REQUEST_URI is the only important one. It's the URL, it tells you everything you need to know for dynamic web serving.
BIGGER EXAMPLE WITH THREADING
fcgi example with threads, plus it can be shut down by ctrl-c. 61 lines of code.
A note on threading in python: read about the GIL. I wrap the blocking call to accept() so the GIL is released. But if you're doing more work in python than C, you won't get much advantage from being parallel. caveat emptor.
DOCUMENTATION
For now, there is none. Sourceforge probably has some kind of a forum to ask questions, and we'll put together a FAQ section if demand grows.