Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#31737 new enhancement

Unique identifier for Heartbeat API calls

Reported by: ojrask Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 3.6
Component: General Keywords: has-patch needs-testing dev-feedback
Focuses: javascript Cc:


I chose Autosave as it is the most close component to the Heartbeat API.

Currently it seems that the Heartbeat API call made are not differentiated as Heartbeat API calls. The AJAX URL used is the global JS ajaxurl variable and the user agent is the same as the user's browser user-agent.

This makes it difficult to parse them off general server access logs and so on.

Could it be possible to add a query variable (e.g. admin-ajax.php?heartbeat=1) or change/append the user-agent to WordPress Heartbeat API or something?

If a user logs in to wp-admin and leaves the session open, Apache's access.log files will be filled with unwanted clutter originating from the Heartbeat API requests.

With a query variable or a customized user agent server admins could redirect the Heartbeat API traffic logs to a custom log file or even /dev/null if they wish to. This could be possible with the following server directive in Apache for instance:

# Determine user agent, set environment variable depending on it.
SetEnvIfNoCase User-Agent ".*WordPress Heartbeat API.*" heartbeatrequest

# Normal access log, without user-agent checked heartbeat calls.
CustomLog /path/to/access.log combined env=!heartbeatrequest

# Heartbeat calls go to another log file.
CustomLog /path/to/heartbeat.log combined env=heartbeatrequest

I know some Heartbeat API settings can be tinkered with a plugin or a theme using hooks and globals, but I think this addition should be made into the core to keep it consistent across the board.

Attachments (1)

31737.diff (1.2 KB) - added by ojrask 3 years ago.

Download all attachments as: .zip

Change History (4)

#1 @ojrask
3 years ago

  • Severity changed from normal to minor

User-Agent header cannot be changed within $.ajax it seems (possibly related to browser specifics or keeping things consistent). Disregard that Apache User-Agent directive example.

3 years ago

#2 @ojrask
3 years ago

  • Keywords has-patch needs-testing dev-feedback added

31737.diff applies a string append of ?|&heartbeat=1 to the Heartbeat AJAX call URL in heartbeat.js.

Last edited 3 years ago by ojrask (previous) (diff)

#3 @iseulde
3 years ago

  • Component changed from Autosave to General
  • Focuses javascript added
  • Version changed from 4.1.1 to 3.6
Note: See TracTickets for help on using tickets.