he' ); case 'user.logged_in': return __( 'User is logged in', 'w3-total-cache' ); default: return $w3tc_key; } } /** * Appends the database cache status information to the footer comment. * * @param array $strings An array of strings to append additional information to. * * @return array The updated array of strings with appended database cache status. */ public function w3tc_footer_comment( $strings ) { $reject_reason = $this->get_reject_reason(); $append = empty( $reject_reason ) ? '' : sprintf( ' (%1$s)', $reject_reason ); if ( $this->query_hits ) { $strings[] = sprintf( // translators: 1: Query hits, 2: Total queries, 3: Total time, 4: Engine name, 5: Reject reason. __( 'Database Caching %1$d/%2$d queries in %3$.3f seconds using %4$s%5$s', 'w3-total-cache' ), $this->query_hits, $this->query_total, $this->time_total, Cache::engine_name( $this->_config->get_string( 'dbcache.engine' ) ), $append ); } else { $strings[] = sprintf( // translators: 1: Engine name, 2: Reject reason. __( 'Database Caching using %1$s%2$s', 'w3-total-cache' ), Cache::engine_name( $this->_config->get_string( 'dbcache.engine' ) ), $append ); } if ( $this->debug ) { $strings[] = ''; $strings[] = __( 'Db cache debug info:', 'w3-total-cache' ); $strings[] = sprintf( '%1$s%2$d', str_pad( __( 'Total queries: ', 'w3-total-cache' ), 20 ), $this->query_total ); $strings[] = sprintf( '%1$s%2$d', str_pad( __( 'Cached queries: ', 'w3-total-cache' ), 20 ), $this->query_hits ); $strings[] = sprintf( '%1$s%2$.4f', str_pad( __( 'Total query time: ', 'w3-total-cache' ), 20 ), $this->time_total ); } if ( $this->log_filehandle ) { fclose( $this->log_filehandle ); $this->log_filehandle = false; } return $strings; } /** * Records the usage statistics related to the database cache. * * @param object $storage The storage object where the statistics are saved. * * @return void */ public function w3tc_usage_statistics_of_request( $storage ) { $storage->counter_add( 'dbcache_calls_total', $this->query_total ); $storage->counter_add( 'dbcache_calls_hits', $this->query_hits ); $storage->counter_add( 'dbcache_flushes', $this->cache_flushes ); $time_ms = (int) ( $this->time_total * 1000 ); $storage->counter_add( 'dbcache_time_ms', $time_ms ); } /** * Logs a query line to the log file. * * @param array $fields The query info to log. * * @return void */ private function log_query( $fields ) { foreach ( $fields as $i => $field ) { if ( \is_string( $field ) ) { if ( 2 === $i ) { $field = Util_Debug::scrub_sql_literals( $field ); } $fields[ $i ] = Util_Debug::redact( $field ); } } if ( ! $this->log_filehandle ) { $filename = Util_Debug::log_filename( 'dbcache-queries' ); $this->log_filehandle = fopen( $filename, 'a' ); } fputcsv( $this->log_filehandle, $fields, "\t" ); } /** * Check if this is a WP-CLI call and objectcache.engine is using Disk. * * @since 2.8.2 * @access private * * @return bool */ private function is_wpcli_disk(): bool { $is_engine_disk = 'file' === $this->_config->get_string( 'dbcache.engine' ); $is_wpcli_disk = $this->_config->get_boolean( 'dbcache.wpcli_disk' ); return defined( 'WP_CLI' ) && \WP_CLI && $is_engine_disk && ! $is_wpcli_disk; } }