-
Notifications
You must be signed in to change notification settings - Fork 104
/
batcache-stats-example.php
32 lines (27 loc) · 1.09 KB
/
batcache-stats-example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* This is a copy of our Batcache-stats.php file but it is suffixed so that you don't use it by default.
* You probably don't want huge log files filling up your server by default, but this gives you and idea
* of how we use this function. We have a separate parsing script that comes along and reads these files
* and enters them into our internal stats.
*/
if ( !function_exists( 'batcache_stats' ) ) {
function batcache_stats( $name, $value, $num = 1, $today = FALSE, $hour = FALSE ) {
if ( !$today )
$today = gmdate( 'Y-m-d' );
if ( !$hour )
$hour = gmdate( 'Y-m-d H:00:00' );
// batcache never loads wpdb so always do this async
if ( !file_exists( '/var/spool/wpcom/extra' ) )
mkdir( '/var/spool/wpcom/extra', 0777 );
$value = rawurlencode( $value );
$stats_filename = "/var/spool/wpcom/extra/{$today}_" . gmdate( 'H' . '-' . 'i' );
if ( ! file_exists( $stats_filename ) ) {
touch( $stats_filename );
chmod( $stats_filename, 0777 );
}
$fp = fopen( $stats_filename, 'a' );
fwrite( $fp, "{$hour}\t{$name}\t{$value}\t{$num}" . chr( 10 ) );
fclose( $fp );
}
}