0

I'm porting an IIS asapi filter over to linux/apache, and am wondering what the best path to take it. On IIS, this isapi filter intercepts the request, performs a database lookup to find the file the user is requesting, and then rewrites the URL to directly serve that file.

What is the best way to do this on Apache? mod_rewrite doesn't seem to have a facility to interject user code to perform a database lookup, so we can't use that. We can't use the mod_isapi since our DLL is a filter and the module doesn't support that.

Right now, I'm thinking the most straightforward way is to write our own C module, using the mod_rewrite code as a guide. I'd like to avoid that if I can. I also don't want to have to issue an HTTP redirect for each request via a perl/PHP/whatever script since performance will suffer with the redirect.

Suggestions? Can we use Apache handlers or filters to accomplish this?

1 Answer 1

2

In mod_rewrite, The MapType "prg" is meant to do exactly this. It lets you use any executable file as your map, all your program has to do is read in strings and output the lookup value.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

5
  • Thanks, I'll look into this. Do you know if there are any performance hits with using this? Can the external application be cached somehow? I see that the responses can be cached, but I'm not sure if that fits our needs or if it will help us. Commented Jan 4, 2011 at 18:09
  • The external app needs to be responsible for its own caching. This can and does scale well, provided your external app can keep up with incoming requests.
    – Zeki
    Commented Jan 4, 2011 at 18:32
  • Interesting. Is the external application loaded into memory for each request? Considering that we'll be making a connection to a database, it sounds like it'd be best to have it be persistent somehow. Commented Jan 4, 2011 at 22:02
  • No, the external app is loaded once and is shared by all of the threads. Since it only runs in 1 thread (or at least that's how it was in 1.3), it needs to be very fast and very lightweight. If you are going to hit a database, consider using local memory to store the top traffic lookups so that you cut down your database traffic. You could also consider using memcached or something as a middle tier so that the database doesn't get clobbered.
    – Zeki
    Commented Jan 4, 2011 at 23:55
  • Thanks. Found a good example here: codemarvels.com/2010/11/… Commented Jan 5, 2011 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.