473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Log File - Counting "Hits"

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
2 1440
> 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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

68
by: Marco Bubke | last post by:
Hi I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly. def foo(x, y): pass I call this foo(1, 2), this isn't really intuitive to me! Also I...
10
by: ST | last post by:
Hi, I'm new to vb.net programming, and I keep getting this error: Name 'GetQuery' is not declared. I can't figure out why?? It seems like I have the right references/namespaces. This is my code...
32
by: Christopher Benson-Manica | last post by:
Is the following code legal, moral, and advisable? #include <iostream> class A { private: int a; public: A() : a(42) {}
4
by: N. Graves | last post by:
First... thanks for taking time to read my quest. I have Access database that I have created that once it has been deployed I will not know who has it or who is using it. This is my idea but...
0
by: alex bean | last post by:
Is there a performance counter or something that I can use to determine the number of "hits" there have been to webmethod and if it ended in success of failure (exception/soapfault). Essentially,...
0
by: sebnunes | last post by:
Hi all, I have a strange behavior here. I'm debugging a web page. When I set a breakpoint in the file the debugger hits the breakpoint but if I try run further the page crashes and The error...
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what...
0
by: Jeff Groves | last post by:
I'm using FreezePython on a Python program that uses wxPython and subprocess. The result almost works, but it always hits this bug: File "velauncher.py", line 847, in Launch File...
5
by: AAaron123 | last post by:
The aspx file includes the following: <asp:LoginView ID="LoginView1" Runat="server"> <LoggedInTemplate> <fieldset> <asp:label id="message1" runat="server" />
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.