By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Log File - Counting "Hits"

P: n/a
Hi. I have a script that runs every night on my server that counts the
hits for my hosted RSS feeds and puts the information into a MySQL
table which then feeds the live(ish) statistics graphs on the site.

I am using:

$log=implode('',file("access_log"));
$count=substr_count($log,"GET /feed7.xml");

for example to count the number of times feed7.xml is requested.

As the popularity of my site increases, however, I have started to
notice these errors in the error log:

PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried
to allocate 10802165 bytes) in

I know I could increase the memory settings in PHP - but is there a
smarter way of counting entries in the log file without trying to load
the entire thing into memory first?

Thanks, in anticipation

Steve

Jun 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> I know I could increase the memory settings in PHP - but is there a
smarter way of counting entries in the log file without trying to load
the entire thing into memory first?


You could read the file in line by line and count as you go using fopen()
and fread() or fgets() .. See the PHP pages for how to use them.

Alternatively you could make a system call with "grep 'GET /feed7.xml' | wc -l"

Ben
Jun 27 '06 #2

P: n/a

Ben Holness wrote:
You could read the file in line by line and count as you go using fopen()
and fread() or fgets() .. See the PHP pages for how to use them.

Alternatively you could make a system call with "grep 'GET /feed7.xml' | wc -l"

Ben

Thanks. I used the grep command.

Thanks for all your help.

Steve

Jun 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.