OT: php question.

Ion-Mihai Tetcu itetcu at apropo.ro
Mon Feb 2 18:54:17 PST 2004


On Mon, 2 Feb 2004 17:28:59 -0800
Gary Kline <kline at thought.org> wrote:

> 	Is there a way of having <? php code ?> print the name of 
> 	its file (along with the number of hits for tht file) and
> 	keep track of all the files in a $WWW_ROOT/filecount page?
> 
> 	Right now I have a cgi script tracking over 100 individual
> 	file with
> 
> 	filename1	hitcount1
> 	filename2	hitcount2
> 	...
> 	filenameN	hitcountN
> 
> 	This question came about when I realized that I've got
> 	more than 30K hits on *all* my pages in the past 22 months.
> 
> 	Of course, I could hand-code each individual filename  and
> 	call the counter code. Isn' there a more automagic way?

$_SERVER["SCRIPT_FILENAME"] /usr/local/psa/home/vhosts/some_host.ro/httpdocs/phpinfo.php
$_SERVER["REQUEST_URI"]	/phpinfo.php 	
$_SERVER["SCRIPT_NAME"]	/phpinfo.php 	
$_SERVER["PATH_TRANSLATED"]/usr/local/psa/home/vhosts/some_host.ro/httpdocs/phpinfo.php 	
$_SERVER["PHP_SELF"]	/phpinfo.php 

I would suggest only echo-ing a line per file per hit and do a wc -l
when needed; or echo the SCRIPT_FILENAME in a single file and do a grep
$SCRIPT_FILENAME | wc -l when needed. Of course, you can optimise this
(e.g. monthly doing accounting and deleteing the content of the log).
This way is much faster that reading current count for the page,
incrementing and writing it back.

This is far for being the best way, esp. under load, but will do the
trick.



-- 
IOnut
Unregistered ;) FreeBSD user


More information about the freebsd-questions mailing list