Running your static pages thru php shouldn't slow it down.
There is a slight overhead, and that can add up for lots of simultanous views.
On an server with a high load, why make a static html page require any more cpu attention than it really needs?
This is just an idea. Not sure if it would be effective or make any difference...
// flush to the browser
// now do all your time-consuming PHP stuff
Yeah I was thinking about the flush command that I had vaguely remembered seeing.
Is there also a command to forcefully close the connection so the server is completely done with the visitor before the code begins the other housekeeping?
|Is there any clever way I can use apache (possibly a module in htaccess?) to simply execute the php script AFTER any html page is delivered to a user |
I might be taking you literally but page is not delivered until all its components were delivered, ie: images, css etc. If you want to run PHP function after that all happens then you can just insert web bug, which would call PHP script that will do some work (log?) and then return 30-40 bytes of invisible GIF.
If however you meant to do some work BEFORE html file is fully delivered then you can use methods described above.
Oooh that's an interesting thought I had forgotten about, a pseudo image that runs as the php code as an element of the page.
Many third party tracking programs use that technique but since this is my own code I could make it work better.
I can make the image name include the source page name so that it doesn't rely on referers which can be blocked.
But what about folks who block certain kinds of images and the problem of image caching. I know I can make the php script always look new to the browser but sometimes they cache or block the image anyway. Hmnm....
|But what about folks who block certain kinds of images and the problem of image caching. |
Beat caching by specifying unique name for the image on every page, or append?datestamp to URL - it won't affect nothing. This image can be used for legitimate purpose - some web designers use invisible images and stretch them to create filled rectangles (can't find better term).
So long as its not a 3rd party web bug, and especially functional element of a page it should not be blocked. Word of warning though - referer will be set to that of page for the image request, so you won't get original referer.
Are you trying to log something that Apache can't already log for you?
Ideally, something like this would work:
AddOutputFilter PHP .html
AddInputFilter PHP .html
php_value auto_append_file /path/logger.php
<? error_log("hello, world");?>
But unfortunately not only does this send the whole page through PHP for parsing, but PHP also removes the Last-Modified etc. that static serving sets.
You can do this easily with Perl and mod_perl though.
You can attach a function to run after the content-sending phase. Apache will do everything just like it normally does for static serving- no overhead added- and run your function after the connection is closed. (PerlLogHandler)
It's very, very fast, but you will need to spend some time managing your RAM usage.
Very interesting jollymcfats, exactly what I hoped some apache guru would know.
Even thought it's not perfect, it's a great start for research.