public static function w3tc_ajax_cdn_highwinds_widgetdata() { try { $core = Dispatcher::component('Cdn_Core'); $cdn = $core->get_cdn(); $analytics = $cdn->service_analytics_transfer(); $sum_mbytes = 0; $sum_mbps = 0; $sum_rps = 0; $graph = array(array('Date', 'Requests')); $count = count($analytics); foreach ($analytics as $item) { $sum_mbytes += $item['xferUsedTotalMB']; $sum_mbps += $item['xferRateMeanMbps']; $sum_rps += $item['rpsMean']; $graph[] = array(gmdate('d M', $item['usageTime'] / 1000), $item['requestsCountTotal']); } $response = array('transferred_size' => Util_Ui::format_mbytes($sum_mbytes / $count), 'average_mbps' => sprintf('%.2f', $sum_mbps / $count), 'average_rps' => sprintf('%.2f', $sum_rps / $count), 'graph' => $graph); echo json_encode($response); } catch (\Exception $e) { echo json_encode(array('error' => $e->getMessage())); } }