我认为节拍本质上是交错的,因为下一个节拍是由浏览器时间决定的time()
在scheduleNextTick()
中的方法/wp-includes/js/heartbeat.js
文件:
var delta = time() - settings.lastTick,
interval = settings.mainInterval;
用来安排下一个勾号的
setTimeout
功能:
if ( delta < interval ) {
settings.beatTimer = window.setTimeout(
function() {
connect();
},
interval - delta
);
} else {
connect();
}
浏览器时间定义为:
function time() {
return (new Date()).getTime();
}
The
connect()
方法包含ajax调用和使用
always()
.always( function() {
settings.connecting = false;
scheduleNextTick();
})
安排下一个勾号。
可用的刻度间隔为5s、15s、30s和60s。
对于大量非常活跃的用户,在短时间间隔内,节拍可能同时发生。
有一些数据总是很好的,因此您可以使用heartbeat_tick
挂钩:
add_action( \'heartbeat_tick\',
function( $response, $screen_id )
{
$file = WP_CONTENT_DIR . \'/ticks.log\'; // Edit this filepath to your needs.
if( file_exists( $file ) && is_writeable( $file ) )
{
file_put_contents(
$file,
sprintf( "%s - Tick from user_id : %d - from screen_id : %s" . PHP_EOL,
date( \'c\' ),
get_current_user_id(),
$screen_id
),
FILE_APPEND | LOCK_EX
);
}
}
, 11, 2 );
下面是
ticks.log
文件:
2014-09-01T12:41:04+00:00 - Tick from user_id : 1 - from screen_id : edit-post
2014-09-01T12:41:19+00:00 - Tick from user_id : 1 - from screen_id : edit-post
2014-09-01T12:41:34+00:00 - Tick from user_id : 1 - from screen_id : edit-post
2014-09-01T12:41:56+00:00 - Tick from user_id : 1 - from screen_id : post
2014-09-01T12:42:11+00:00 - Tick from user_id : 1 - from screen_id : post
2014-09-01T12:42:20+00:00 - Tick from user_id : 3 - from screen_id : upload
2014-09-01T12:42:38+00:00 - Tick from user_id : 1 - from screen_id : post
2014-09-01T12:43:05+00:00 - Tick from user_id : 1 - from screen_id : post
2014-09-01T12:43:08+00:00 - Tick from user_id : 3 - from screen_id : attachment
2014-09-01T12:43:20+00:00 - Tick from user_id : 1 - from screen_id : post
2014-09-01T12:43:36+00:00 - Tick from user_id : 1 - from screen_id : post
2014-09-01T12:44:17+00:00 - Tick from user_id : 3 - from screen_id : profile