In support of adding hook_page_not_found() to Drupal 7
I want to try and get a hook_page_not_found() to Drupal 7.
I've taken this snippet from http://drupal.org/node/444756
I have only just started this but I wanted to post for opinion. In IRC I was pushed towards using hook_page_alter() instead of defining a new hook. However hook_page_alter() runs after the 404 header has been sent. I don't expect the code as is to get in. Largely I am posting this as a start because I work on large sites (Economist.com) and I don't want to have to use nfs to share the files directory as it adds another single point of failure in the stack.
Background for wanting hook_page_not_found()
The approach that Vignette and other large cm systems take is as follows.
Server X and Y are physical or logical Drupal servers that share the same codebase and database.
1) User A uploads an image ( sites/default/dog.png ) to server X to be included onto node/1234.
2) User B loads node/1234 on server Y. When the request comes into load sites/default/dog.png it fires a Drupal 404 page. If hook_404() exists a module of some sort could look up whether the file exists in the files table and go collect the image from the correct server, write the image locally and either serve the image or redirect to it. I am intentionally vague on how the module would collect the image from Server Y or Z or Q as this is an example use case.
2) User C loads node/1234 on server Y. When the request comes into load sites/default/dog.png the file exists and is served by the webserver. Apache never gets involved.
This approach doesn't need each upload to jump through hoops to put each file uploaded on each server which is fast for the person uploading. It doesn't require a cron job to push the relevant files around which would have time lag issues anyway.
Attached is a gz file, beautifully mangled by Drupal on upload and the two files in that mangled gz file that provide a sample module that could use hook_page_not_found()