homepage Welcome to WebmasterWorld Guest from 54.167.244.71
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
running php function AFTER page is delivered
keeping pages static but allow tracking, etc
amznVibe




msg:1315860
 3:37 pm on Aug 18, 2004 (gmt 0)

One of my websites is composed of all static pages.

I've got a php include that I have inserted at the end of the pages to do tracking and other housekeeping, but it doesn't output anything to the page itself.

Unfortunately this still forces me to put all the pages through the php interpretor.

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, therefore keeping their access speedy and a side benefit of truly keeping the pages static, complete with etags, content-length and "last modified"?

Thanks for any ideas!

 

JasonHamilton




msg:1315861
 3:47 pm on Aug 18, 2004 (gmt 0)

Running your static pages thru php shouldn't slow it down.

amznVibe




msg:1315862
 4:03 pm on Aug 18, 2004 (gmt 0)

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?

httpwebwitch




msg:1315863
 4:07 pm on Aug 18, 2004 (gmt 0)

This is just an idea. Not sure if it would be effective or make any difference...

plain HTML
plain HTML
plain HTML
plain HTML
plain HTML
plain HTML
plain HTML
plain HTML

<?php
// flush to the browser
flush();
// now do all your time-consuming PHP stuff
do_infinite_loop($forever);
?>

amznVibe




msg:1315864
 4:08 pm on Aug 18, 2004 (gmt 0)

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?

Lord Majestic




msg:1315865
 4:14 pm on Aug 18, 2004 (gmt 0)

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.

amznVibe




msg:1315866
 4:20 pm on Aug 18, 2004 (gmt 0)

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....

Lord Majestic




msg:1315867
 4:26 pm on Aug 18, 2004 (gmt 0)

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.

py9jmas




msg:1315868
 5:09 pm on Aug 18, 2004 (gmt 0)

Are you trying to log something that Apache can't already log for you?

[httpd.apache.org...]

jollymcfats




msg:1315869
 5:13 pm on Aug 18, 2004 (gmt 0)

Ideally, something like this would work:

apache config:
<Files *.html>
AddOutputFilter PHP .html
AddInputFilter PHP .html
</Files>
php_value auto_append_file /path/logger.php

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.

amznVibe




msg:1315870
 5:10 am on Aug 19, 2004 (gmt 0)

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.

Many thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved