b2evolution b2evolution

  • Sign in
  • Sign up
  • About
  • Downloads
  • Hosting
  • Docs
  • Support
  • Sign in
  • Sign up
  • Manuals Home
  • Latest Updates
 
  1. b2evolution CMS User Manual
  2. Developer Reference
  3. Scheduled Tasks Reference
  4. Prune old hits & sessions (includes OPTIMIZE)

Prune old hits & sessions (includes OPTIMIZE)

This task will avoid that your sessions and hitlog tables grow indefinitely. It should typically run once a day (preferably at a low traffic time for your site).

The parameter Auto pruning must be set to "With a scheduled job"; otherwise the task will do nothing. For more details, please read this page: Hit & Session Logging Panel.

Settings

Prune old hits & sessions (includes OPTIMIZE)
  • Keep detailed logs for: (default 15 days) . The number of days of hitlog and sessions to keep. Note: this setting is also duplicated in Analytics > Settings.
  • In Users > Settings > Profiles there is another setting: Session timeout: (default 7days). This value defines when a session expires and becomes available to be pruned.

This means that:

  • Anonymous sessions will be pruned after "Keep detailed logs for:" (default: 15 days)
  • Logged-in sessions will be pruned after the longest period of "Keep detailed logs for:" AND "Session timeout:".
  • The hitlog (individual hits) will be pruned after "Keep detailed logs for:" (default: 15 days)

Performance

Important: The bigger you make the above settings, the bigger your sessions table will grow and the more time it will take to prune it daily. This will also significantly increase the size of your backups. Don’t let this table grow too large.

This task can take a very long time to execute, depending on the size of your session, goal hits and hitlog tables.

  • If you have not run that task for a long time, your tables may be so large that MySQL will choke itself when trying to prune them. In such a case, it may be a good idea to TRUNCATE the tables using phpMyAdmin and then set this task to run on a daily basis.
  • If your site is receiving a lot of daily traffic and MySQL chokes every night when trying to prune, your options are to either upgrade your web server or to log less data by lowering the settings above.

Technical details

This code performs 4 main actions:

Pruning the Hitlog

Prune T_hitlog based on the number of days to keep.

Before pruning, the data is aggregated on a daily basis and kept in T_hits__aggregate.

Pruning the Goal Hits

Prune T_track__goalhit based on the number of days to keep.

Before pruning, the data is aggregated on a daily basis and kept in T_track__goalhit_aggregate.

Pruning Expired Sessions

Prune timed-out T_sessions older than number of days to keep.

Before pruning, the data is aggregated on a daily basis and kept in T_hits__aggregate_sessions.

Note: old sessions that have not timed out yet will be kept in the DB.

The decision about which sessions are timed out or not is based on the value of this field: T_sessions.sess_lastseen_ts; it stores the last timestamp for any activity on this session. All the sessions where lastseen_ts exceeds the sessions expiration time and also reach the hitlog keep number of days described above, will be pruned.

Note: if a custom session expiration delay is set for a user, it cannot be longer than the pruning expiration time, because at that point the session will be deleted from the DB.

Before pruning sessions, a BeforeSessionsDelete event is triggered to all the plugins in the site, and the behavior of the task could be affected if at least one of those plugins takes some action on the sessions data. This could be your first target when detecting an issue with this task.

The section of the code that manages the sessions data deletion performs three tasks:

  1. Calculates the cutoff date. All sessions inactive beyond that date will be deleted.
  2. Triggers the event "BeforeSessionsDelete" to all plugins.
  3. Delete all the sessions beyond the date obtained in 1.

Pruning Basedomains

Prune T_basedomains that are not used by any hit/session

Optimizing the database

MYSQL OPTIMIZE the tables:

  • T_hitlog
  • T_track__goalhit
  • T_sessions
  • T_basedomains
Created by fplanque • Last edit by fplanque on 2020-06-09 00:20 • •

No feedback yet

On this page

  • Settings
  • Performance
  • Technical details
  • Pruning the Hitlog
  • Pruning the Goal Hits
  • Pruning Expired Sessions
  • Pruning Basedomains
  • Optimizing the database

Search the Manual

Content Hierarchy

  • b2evolution CMS User Manual
  • User's Guide
  • Installation / Upgrade
  • Front-office Reference
  • Back-office Reference
  • Developer Reference
    • Website Skins/Themes
    • Email Skins/Themes
    • b2evolution Files
    • Website Integration
    • Plugins
    • Debugging
    • Technical Reference
    • Hacks
    • Credits
    • Development
    • How to... (Customize)
    • Scheduled Tasks Reference
      • Poll the antispam blacklist
      • Process the return path inbox
      • Manage email address statuses
      • Send reminders about non-activated accounts
      • Send reminders about inactive accounts
      • Execute automations
      • Create posts by email
      • Send notifications about new comment on «item title»
      • Send notifications for «item title»
      • Send a chunk of emails for the campaign "email campaign name"
      • Send reminders about comments awaiting moderation
      • Send reminders about posts awaiting moderation
      • Monthly alert on stale contents
      • Extract info from hit log ("Process hit log")
      • Prune old hits & sessions (includes OPTIMIZE)
      • Send reminders about unread messages
      • Basic test job
      • Error test job
      • Clean up scheduled jobs older than a threshold
      • Clean up email logs older than a threshold
      • Heavy DB maintenance (CHECK & OPTIMIZE)
      • Light DB maintenance (ANALYZE)
      • Prune old files from page cache
      • Prune recycled comments
  • Operations Reference
  • Advanced Topics
  • Glossary
  • Archives
Responsive CMS

This online manual is powered by b2evolution CMS – A complete engine for your website.

About b2evolution

  • What is it?
  • Features
  • Getting Started
  • Screenshots
  • Online demo
  • Testimonials
  • Design philosophy
  • Free & open source
  • Terms of service

Downloads

  • Latest releases
  • Skins
  • Plugins
  • Language packs

About us

  • About us
  • Contact

Webhosting Guide

  • Web hosting blog
  • Best web hosting
  • Cheap web hosting
  • Green web hosting
  • Hosting with SSH
  • VPS hosting
  • Dedicated servers
  • Reseller hosting
  • Int'l: UK / France

Docs & Support

  • Online manual
  • Forums
  • Hire a pro !

Other

  • Adsense
  • Press room
  • Privacy policy

Stay in touch

  • GitHub
  • Twitter
  • Facebook
  • LinkedIn
  • News blog
  • RSS feed
  • Atom feed

Founded & Maintained by François Planque