Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Script That Gets Information Every 10 Seconds ...

ajax

  • Please log in to reply
15 replies to this topic

#13 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 31 July 2011 - 06:35 PM

The thing is, unless there is a way to set up separate sessions for each tab (if the person has multiple tabs open to that site), I want to find some other way.

The website normally doesn't get too many visits, with maybe up to 25 users a few times a week.

I changed the frequency to once every 60 seconds. I don't know if that's too small of a value or not.

But the other thing I did, is that I made the PHP script check the $_SERVER["HTTP_REFERER"] (it's actually spelled "referrer") (I don't know why HTTP decided to spell it another way) and see which page the browser was on last. Then the PHP code deletes one entry under that URL from the records.

It doesn't really work if the user manually types another URL into the address bar, though; any other ways I could find out which page the browser was open to, previously?
  • 0

#14 webcodez

webcodez

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 143 posts

Posted 01 August 2011 - 03:39 AM

I would suggest not to make your visitor stats accumulated over the last 10 seconds because, as mentioned already, when you get lots of traffic to your website, your server will get loaded heavily with MySQL activities ( I mean, imagine: for each visitor there'll be a query every 10 seconds, so for a visitor who views your website for 15 minutes it would be already like 90 queries just for the stats ). Rather have 1 log query a time, then have visitors stats over the last 15 minutes or something. However I'm not quite sure what your needs are and why it has to be every 10 seconds, but these are just my thoughts ^^.

EDIT: didn't read your latest post, 60 seconds seems alright, especially with your amount of visitors there should be no problems there :D
Also I think it would only be more server load to have the previous row deleted ( correct me if I'm wrong ) because one MySQL table can carry a LOT of rows, so there's no need to delete previous rows. You could perhaps make a cronjob script though, that deletes all the entries with, say, timestamp < time()-60, and run this cronjob every day/24 hours. And to check what page the user currently ( or last ) is, check the entry with the latest timestamp.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#15 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 01 August 2011 - 10:04 AM

The idea is, let's say the user went to /index.php

MySQL table:
time=...some_entry...
time=...some_entry...
time=<time1>,script=/index.php,query=,ip=...

Then the user goes to another page. But if we don't delete the row for the page the user was previously viewing, then it would look like the user is viewing two pages at once, which is not true.

So we need to find out what page the user was previously at, and then we need to see if we can delete a row with the matching data.

But then the script on the user's new page would connect to the server and tell the server what new page it is viewing, so that would be entered into the table.

Table:
time=...some_entry...
time=...some_entry...
time=<time2>,script=/some_other_file.php,query=some_query_string,ip=...
  • 0

#16 webcodez

webcodez

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 143 posts

Posted 02 August 2011 - 02:43 AM

However, if a user only views one page at the time, you could just select 1 entry of the user, the one with the highest timestamp ( so the latest one ), or isn't that desired? Like:

SELECT page FROM table WHERE ip = '".$_SERVER['REMOTE_ADDR']."' ORDER BY time DESC LIMIT 1

Also you don't have to know on what page the user previously was because that has to be the entry with the latest timestamp ( or if you already made an entry of the current visit: the 2nd latest timestamp of the user ).
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download