On mod_python
So, I’m getting stuck in to mod_python in a pretty big way at the moment. I’ve never even used mod_perl before, so coming from PHP this is turning out to be a real eye opener.
The key thing to realise about mod_python is that it gives you full control over the whole Apache request. Unlike PHP, you’re not writing scripts that just happen to use Apache as a go between—mod_python exposes a pretty big chunk of Apache’s internal API, and you are expected to hook straight in to it and start doing things. This certainly takes a while to get used to, but comes with some pretty big benefits. For one thing, your code is loaded once (well, once by each Apache process) and stays in memory. This means that global variables within your scripts persist between requests! Unfortunately, each Apache process (of which there are usually quite a few) has its own copy of the code so you can’t use this persistence ability for things like sessions, but it’s great for pooling database connections and keeping unchanging data such as templates in memory.
You can write your own handlers for the various parts of the Apache request. So far I’ve only been playing with the handler that serves up content, but it’s possible to do things like create a handler for the “Authentication” phase that authenticates users in some special way.
My biggest worry at the moment concerns the relative lack of documentation for mod_python on the web—the manual is pretty good, but other than that there’s precious little to get your teeth in to. Luckily the module has a reasonably high traffic mailing list which has so far answered all of the questions I’ve thrown at it promptly and in great detail. I hope to write more about mod_python as I become more comfortable with it. If anyone has any tips, I’d love to hear them.
More recent articles
- Lawyer cites fake cases invented by ChatGPT, judge is not amused - 27th May 2023
- llm, ttok and strip-tags - CLI tools for working with ChatGPT and other LLMs - 18th May 2023
- Delimiters won't save you from prompt injection - 11th May 2023
- Weeknotes: sqlite-utils 3.31, download-esm, Python in a sandbox - 10th May 2023
- Leaked Google document: "We Have No Moat, And Neither Does OpenAI" - 4th May 2023
- Midjourney 5.1 - 4th May 2023
- Prompt injection explained, with video, slides, and a transcript - 2nd May 2023
- download-esm: a tool for downloading ECMAScript modules - 2nd May 2023
- Let's be bear or bunny - 1st May 2023
- Weeknotes: Miscellaneous research into Rye, ChatGPT Code Interpreter and openai-to-sqlite - 1st May 2023