Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3304076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:01:26+00:00 2026-05-17T21:01:26+00:00

I manage a rather large traffic website. On each page we keep track of

  • 0

I manage a rather large traffic website. On each page we keep track of a visitors online by running the following code. We then have a cron which deletes the records which are older than X minutes.

 if(!isset($_SESSION[users_online_id])) {
 if(!(date('H')=='02' && date("i") >= 37 && date("i") <= 45)) {
 # NEW VISITOR - DOESN'T HAVE A USER_ONLINE_ID
  $update_query = "INSERT INTO online SET
  ip_address = '".$visitors_ip_address."',
  datetime = now(),
  user_id = ".$visitor_id.",
  page = '".escape($_SERVER[REQUEST_URI])."',
  area = '".$this_area."',
  type = ".$visitor_type;
  mysql_query($update_query);

  # SET THEIR SESSION VAR FOR NEXT PAGE CHECKING
  $_SESSION[users_online_id] = mysql_insert_id();
 }
     }
     else{
 # USER HAS A SESSION

 # CHECK THAT THE RECORD STILL EXIST
 $check_record = "SELECT COUNT(1) FROM online WHERE id = ".$_SESSION[users_online_id];
 $check_record = mysql_query($check_record);

 if(mysql_result($check_record,0) > 0){
  # IF RECORD STILL EXISIT ( WAS NOT DELETED) UPDATE IT
  $update_query = "UPDATE online SET 
  datetime = now(),
  user_id = ".$visitor_id.",
  page = '".escape($_SERVER[REQUEST_URI])."',
  type = '".$visitor_type."',
  area = '".$this_area."',
  ip_address= '".$visitors_ip_address."'
  WHERE id = '".$_SESSION[users_online_id]."'";
  mysql_query($update_query);
 }
 else if(!(date('H')=='02' && date("i") >= 37 && date("i") <= 45)){
  # IF RECORD WAS DELETED (TO LONG ON 1 PAGE), INSERT A NEW RECORD
  $update_query = "INSERT INTO online SET
  ip_address = '".$visitors_ip_address."',
  datetime = now(),
  user_id = ".$visitor_id.",
  page = '".escape($_SERVER[REQUEST_URI])."',
  area = '".$this_area."',
  type = ".$visitor_type;
  mysql_query($update_query);
  $_SESSION[users_online_id] = mysql_insert_id();
 }
      }

Doing some performace monitoring, i have noticed that queries which interact with this table are starting to take a lot longer to execute. Any ideas on how this can be improved?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:01:26+00:00Added an answer on May 17, 2026 at 9:01 pm

    You may eliminate SELECT query and use UPDATE query and mysql_affected_rows() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I manage a rather large application (50k+ lines of code) by myself, and it
We are using CMake to manage our builds and have a rather large project
I manage a small group and I'd keep my work breakdown in project. However,
I manage a web application for a client with the following specs: ASP.net 3.5
I have a rather large project developed on Sharepoint and Project Server, designed as
I've been leading rather large project that strives to Mavenize various testing apps produced
I'm currently in the planning phase of a rather large project that I'll develop
So basically, I've got a rather large Django project going. It's a private web
When an iPhone application manages its own preferences, rather than using a bundle, it
How would you manage the lifecycle and automated build process when some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.