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

Calculating page bandwidth usage (PHP/Ajax)

P: n/a
Hi,

I intend to use Ajax for a kiosk application, it's primary usage is to
retrieve live data from my DB, it's a fairly small amount of data (5
fields, of small data size and limited to 15 rows).

When I check my server logs I can see that the kiosk page has used a
fair amount of bandwidth this month, this is obviously because a
javascript timeout refreshes the data every 10 seconds. What I need to
know is how to calculate the bandwidth of the data for every ten
seconds and then I can do the math to work out usage hours * bandwidth
per hour.

This is probably a fairly simple task but I've never done it before so
any help would be much appreciated!

Many Thanks

Aug 23 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Aug 23, 6:13 am, FrobinRobin <frobinro...@hotmail.comwrote:
Hi,

I intend to use Ajax for a kiosk application, it's primary usage is to
retrieve live data from my DB, it's a fairly small amount of data (5
fields, of small data size and limited to 15 rows).

When I check my server logs I can see that the kiosk page has used a
fair amount of bandwidth this month, this is obviously because a
javascript timeout refreshes the data every 10 seconds. What I need to
know is how to calculate the bandwidth of the data for every ten
seconds and then I can do the math to work out usage hours * bandwidth
per hour.

This is probably a fairly simple task but I've never done it before so
any help would be much appreciated!

Many Thanks
I'm not entirely sure that PHP is really the best solution to your
problem. There may be a method of measuring bandwidth with PHP, but
probably an easier way would simply be to use a network analyzer, for
example, Ethereal. However, such software has little to do with PHP
programming, so unless you still feel that PHP is the best solution,
further inquiries should be directed to a more fitting newsgroups.

Good luck!

Aug 23 '07 #2

P: n/a
On 23 Aug, 15:37, "burgermeiste...@gmail.com"
<burgermeiste...@gmail.comwrote:
On Aug 23, 6:13 am, FrobinRobin <frobinro...@hotmail.comwrote:


Hi,
I intend to use Ajax for a kiosk application, it's primary usage is to
retrieve live data from my DB, it's a fairly small amount of data (5
fields, of small data size and limited to 15 rows).
When I check my server logs I can see that the kiosk page has used a
fair amount of bandwidth this month, this is obviously because a
javascript timeout refreshes the data every 10 seconds. What I need to
know is how to calculate the bandwidth of the data for every ten
seconds and then I can do the math to work out usage hours * bandwidth
per hour.
This is probably a fairly simple task but I've never done it before so
any help would be much appreciated!
Many Thanks

I'm not entirely sure that PHP is really the best solution to your
problem. There may be a method of measuring bandwidth with PHP, but
probably an easier way would simply be to use a network analyzer, for
example, Ethereal. However, such software has little to do with PHP
programming, so unless you still feel that PHP is the best solution,
further inquiries should be directed to a more fitting newsgroups.

Good luck!- Hide quoted text -

- Show quoted text -
I just want to know how much data each ajax request is - I dont want
to start messing around with third party apps.
How about if I outputted the data to a file then used the filesize()
function? Would that give me the correct data size per ajax request?

Aug 23 '07 #3

P: n/a
FrobinRobin wrote:
On 23 Aug, 15:37, "burgermeiste...@gmail.com"
<burgermeiste...@gmail.comwrote:
>On Aug 23, 6:13 am, FrobinRobin <frobinro...@hotmail.comwrote:


>>Hi,
I intend to use Ajax for a kiosk application, it's primary usage is to
retrieve live data from my DB, it's a fairly small amount of data (5
fields, of small data size and limited to 15 rows).
When I check my server logs I can see that the kiosk page has used a
fair amount of bandwidth this month, this is obviously because a
javascript timeout refreshes the data every 10 seconds. What I need to
know is how to calculate the bandwidth of the data for every ten
seconds and then I can do the math to work out usage hours * bandwidth
per hour.
This is probably a fairly simple task but I've never done it before so
any help would be much appreciated!
Many Thanks
I'm not entirely sure that PHP is really the best solution to your
problem. There may be a method of measuring bandwidth with PHP, but
probably an easier way would simply be to use a network analyzer, for
example, Ethereal. However, such software has little to do with PHP
programming, so unless you still feel that PHP is the best solution,
further inquiries should be directed to a more fitting newsgroups.

Good luck!- Hide quoted text -

- Show quoted text -

I just want to know how much data each ajax request is - I dont want
to start messing around with third party apps.
How about if I outputted the data to a file then used the filesize()
function? Would that give me the correct data size per ajax request?
For text, but not necessarily for the images.

But then polling like you're doing is a very poor practice, anyway. It
puts unnecessary load on the client, server and network.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 23 '07 #4

P: n/a
On Aug 23, 9:54 am, FrobinRobin <frobinro...@hotmail.comwrote:
On 23 Aug, 15:37, "burgermeiste...@gmail.com"

<burgermeiste...@gmail.comwrote:
On Aug 23, 6:13 am, FrobinRobin <frobinro...@hotmail.comwrote:
Hi,
I intend to use Ajax for a kiosk application, it's primary usage is to
retrieve live data from my DB, it's a fairly small amount of data (5
fields, of small data size and limited to 15 rows).
When I check my server logs I can see that the kiosk page has used a
fair amount of bandwidth this month, this is obviously because a
javascript timeout refreshes the data every 10 seconds. What I need to
know is how to calculate the bandwidth of the data for every ten
seconds and then I can do the math to work out usage hours * bandwidth
per hour.
This is probably a fairly simple task but I've never done it before so
any help would be much appreciated!
Many Thanks
I'm not entirely sure that PHP is really the best solution to your
problem. There may be a method of measuring bandwidth with PHP, but
probably an easier way would simply be to use a network analyzer, for
example, Ethereal. However, such software has little to do with PHP
programming, so unless you still feel that PHP is the best solution,
further inquiries should be directed to a more fitting newsgroups.
Good luck!- Hide quoted text -
- Show quoted text -

I just want to know how much data each ajax request is - I dont want
to start messing around with third party apps.
How about if I outputted the data to a file then used the filesize()
function? Would that give me the correct data size per ajax request?
FrobinRobin,

I looked into your situation a little more, and as far as I can see,
directly, with PHP, there is no clear way to measure bandwidth usage.
However, something I overlooked, apache typically keeps an access_log
file which records all requests and the size of the data transferred
in requests. If you're using apache as your web server, reading from
that file is one possible solution. Other web servers may have similar
logs. I'm not sure if the file records the size of the headers sent
though, which is the same concern I have with what you purposed as a
solution, as well as what Jerry mentioned about binaries.

Aug 23 '07 #5

P: n/a
On Aug 23, 9:54 am, FrobinRobin <frobinro...@hotmail.comwrote:
On 23 Aug, 15:37, "burgermeiste...@gmail.com"

<burgermeiste...@gmail.comwrote:
On Aug 23, 6:13 am, FrobinRobin <frobinro...@hotmail.comwrote:
Hi,
I intend to use Ajax for a kiosk application, it's primary usage is to
retrieve live data from my DB, it's a fairly small amount of data (5
fields, of small data size and limited to 15 rows).
When I check my server logs I can see that the kiosk page has used a
fair amount of bandwidth this month, this is obviously because a
javascript timeout refreshes the data every 10 seconds. What I need to
know is how to calculate the bandwidth of the data for every ten
seconds and then I can do the math to work out usage hours * bandwidth
per hour.
This is probably a fairly simple task but I've never done it before so
any help would be much appreciated!
Many Thanks
I'm not entirely sure that PHP is really the best solution to your
problem. There may be a method of measuring bandwidth with PHP, but
probably an easier way would simply be to use a network analyzer, for
example, Ethereal. However, such software has little to do with PHP
programming, so unless you still feel that PHP is the best solution,
further inquiries should be directed to a more fitting newsgroups.
Good luck!- Hide quoted text -
- Show quoted text -

I just want to know how much data each ajax request is - I dont want
to start messing around with third party apps.
How about if I outputted the data to a file then used the filesize()
function? Would that give me the correct data size per ajax request?
Oh, and one other thing, just for the record, Ethereal is free and
relatively easy to use, so I can't say I entirely understand your
reluctance to try it.

Aug 23 '07 #6

P: n/a
ok, thanks for the responses.

In reply to burgermeister01 I've already checked the server logs and
they give me the bandwidth overview of file requests; not just the
Ajax part which I want. I fear this is the same info Ethereal will
give me plus I do not want to waste time with a new app.. so I prefer
not to get involved with it; but thanks for the help, it is certainly
noted for future reference.

I've calculated an average 10kb for each ajax request using the
filesize function, polling every ten seconds equates to 1KB/s, which
doesnt seem that bad. However, this application will serve a few
hundred kiosks so even 1KB/s is a lot.

I appreciate what Jerry is saying about load on client, server and
network and all of the Ajax calls that are getting the same data is a
really bad waste (damn ur always right Jerry!). Maybe if I changed the
script to compare the local client data against the server data using
a DB SELECT and then download only the changes? This would at least
limit some wasted bandwidth. (Your comments Jerry are always
appreciated)

I know this is all about the way the http protocol works, hence why I
introduced Ajax, apart from the wastage it seemed like the right
idea.
So maybe a server process (which I've heard of but have no real PHP
integration experience with) that would monitor the DB and prompt? the
client to update? Considering I have full control over the kiosk I
could even connect directly to it and maybe use files (xml maybe)
instead of a database? Seems as its only 10-15 records with five small
fields in it?

Any pointers in the right direction would be very appreciated.

Aug 23 '07 #7

P: n/a
FrobinRobin wrote:
ok, thanks for the responses.

In reply to burgermeister01 I've already checked the server logs and
they give me the bandwidth overview of file requests; not just the
Ajax part which I want. I fear this is the same info Ethereal will
give me plus I do not want to waste time with a new app.. so I prefer
not to get involved with it; but thanks for the help, it is certainly
noted for future reference.

I've calculated an average 10kb for each ajax request using the
filesize function, polling every ten seconds equates to 1KB/s, which
doesnt seem that bad. However, this application will serve a few
hundred kiosks so even 1KB/s is a lot.

I appreciate what Jerry is saying about load on client, server and
network and all of the Ajax calls that are getting the same data is a
really bad waste (damn ur always right Jerry!). Maybe if I changed the
script to compare the local client data against the server data using
a DB SELECT and then download only the changes? This would at least
limit some wasted bandwidth. (Your comments Jerry are always
appreciated)

I know this is all about the way the http protocol works, hence why I
introduced Ajax, apart from the wastage it seemed like the right
idea.
So maybe a server process (which I've heard of but have no real PHP
integration experience with) that would monitor the DB and prompt? the
client to update? Considering I have full control over the kiosk I
could even connect directly to it and maybe use files (xml maybe)
instead of a database? Seems as its only 10-15 records with five small
fields in it?

Any pointers in the right direction would be very appreciated.
Well, you could use Ajax to poll a special page which returns just "y"
or "n", as to whether something has changed. Pass a unique id for the
kiosk and let the server determine if something has changed. If it has,
Ajax can return a new page.

More server side processing, but even with the header info going back
and forth, total traffic should be much less.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 24 '07 #8

P: n/a
FrobinRobin wrote:
I fear this is the same info Ethereal will give me plus I do not want to
waste time with a new app.
Really Ethereal (which is actually called "Wireshark" now -- it was
renamed over a year ago) will give you exactly the information you need:
the exact number of bytes being transmitted, including not just the data
and HTTP headers, but also the overhead added by TCP/IP.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 64 days, 12:07.]

TrivialEncoder/0.2
http://tobyinkster.co.uk/blog/2007/0...ivial-encoder/
Aug 24 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.