I perfectly know how to create a custom 404 page in PHP, however I'm wondering if there's a way to give back control to to apache and let it produce the proper 404 page, sending right headers, etc. when my logic says so?
I'm looking at some apache specific functions but can't seem to find anything appropriate. Is that really just not possible? I recall something similar available to e.g. mod_perl by having full access to apache internals, where's that equivalent in PHP?
My research so far led me to the conclusion that it's not possible to delegate back to Apache from within mod_php like some other technologies, e.g. mod_perl, allow.
I'm not sure you can do what you want to do exactly, but one of your requirements can be met by php, and well, apart from ... I don't really see any other ones.
You can send the correct type of header using the header() function. In my code I usually use the one below.
header("HTTP/1.0 404 Not Found");
echo "sorry, page not found...";
See function.header.php in the php manual for more details.