crawler = Crawler2::cls();
}
/**
* List all crawlers
*
* Displays a table of all crawlers with their details.
*
* ## OPTIONS
*
* ## EXAMPLES
*
* # List all crawlers
* $ wp litespeed-crawler l
*
* @since 1.1.0
*/
public function l() {
$this->list();
}
/**
* List all crawlers
*
* Displays a table of all crawlers with their details.
*
* ## OPTIONS
*
* ## EXAMPLES
*
* # List all crawlers
* $ wp litespeed-crawler list
*
* @since 1.1.0
*/
public function list() {
$crawler_list = $this->crawler->list_crawlers();
$summary = Crawler2::get_summary();
if ($summary['curr_crawler'] >= count($crawler_list)) {
$summary['curr_crawler'] = 0;
}
$is_running = time() - $summary['is_running'] <= 900;
$crawler_run_interval = defined('LITESPEED_CRAWLER_RUN_INTERVAL') ? LITESPEED_CRAWLER_RUN_INTERVAL : 600; // Specify time in seconds for the time between each run interval
if ($crawler_run_interval > 0) {
$recurrence = '';
$hours = (int) floor($crawler_run_interval / 3600);
if ($hours) {
if ($hours > 1) {
$recurrence .= sprintf(__('%d hours', 'litespeed-cache'), $hours);
} else {
$recurrence .= sprintf(__('%d hour', 'litespeed-cache'), $hours);
}
}
$minutes = (int) floor(($crawler_run_interval % 3600) / 60);
if ($minutes) {
$recurrence .= ' ';
if ($minutes > 1) {
$recurrence .= sprintf(__('%d minutes', 'litespeed-cache'), $minutes);
} else {
$recurrence .= sprintf(__('%d minute', 'litespeed-cache'), $minutes);
}
}
}
$list = array();
foreach ($crawler_list as $i => $v) {
$hit = !empty($summary['crawler_stats'][$i][Crawler2::STATUS_HIT]) ? $summary['crawler_stats'][$i][Crawler2::STATUS_HIT] : 0;
$miss = !empty($summary['crawler_stats'][$i][Crawler2::STATUS_MISS]) ? $summary['crawler_stats'][$i][Crawler2::STATUS_MISS] : 0;
$blacklisted = !empty($summary['crawler_stats'][$i][Crawler2::STATUS_BLACKLIST]) ? $summary['crawler_stats'][$i][Crawler2::STATUS_BLACKLIST] : 0;
$blacklisted += !empty($summary['crawler_stats'][$i][Crawler2::STATUS_NOCACHE]) ? $summary['crawler_stats'][$i][Crawler2::STATUS_NOCACHE] : 0;
if (isset($summary['crawler_stats'][$i][Crawler2::STATUS_WAIT])) {
$waiting = $summary['crawler_stats'][$i][Crawler2::STATUS_WAIT] ?? 0;
} else {
$waiting = $summary['list_size'] - $hit - $miss - $blacklisted;
}
$analytics = 'Waiting: ' . $waiting;
$analytics .= ' Hit: ' . $hit;
$analytics .= ' Miss: ' . $miss;
$analytics .= ' Blocked: ' . $blacklisted;
$running = '';
if ($i === $summary['curr_crawler']) {
$running = 'Pos: ' . ($summary['last_pos'] + 1);
if ($is_running) {
$running .= '(Running)';
}
}
$status = $this->crawler->is_active($i) ? '✅' : '❌';
$list[] = array(
'ID' => $i + 1,
'Name' => wp_strip_all_tags($v['title']),
'Frequency' => $recurrence,
'Status' => $status,
'Analytics' => $analytics,
'Running' => $running,
);
}
WP_CLI\Utils\format_items('table', $list, array( 'ID', 'Name', 'Frequency', 'Status', 'Analytics', 'Running' ));
}
/**
* Enable one crawler
*
* ## OPTIONS
*
*