/** * Fetch a web resource by URL * @param string $url The HTTP URL that the request is being made to * @param array $options Any PHP cURL options that are needed * @return object An object with properties of 'url', 'body', and 'status' */ public static function fetch($url, $options = array()) { if (!function_exists('curl_exec')) { WPSearch_Log::add('error', "cURL is not installed! Throwing an exception.."); throw new WPSearch_Exception("The cURL module must be installed"); } $curl_handle = curl_init($url); $options += array(CURLOPT_RETURNTRANSFER => true); curl_setopt_array($curl_handle, $options); $timer = "Call to {$url} via HTTP"; WPSearch_Benchmark::start($timer); $body = curl_exec($curl_handle); $status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE); WPSearch_Benchmark::stop($timer); return (object) array('url' => $url, 'body' => $body, 'status' => $status); }
/** * Get information about when the last index was built, whether it is * currently running a full build, and it's progress */ public function getStats() { $timer = "Function " . __CLASS__ . "::getStats()"; WPSearch_Benchmark::start($timer); $status = $this->_getStatusInfo(); $index = $this->_getIndex(); if (!$status) { $status = array(); $status['last_rebuild'] = $this->_getRebuildTime(); $status['reindexing'] = false; } $status['total'] = WPSearch_Model::getPublishedPostCount(); if ($index) { $status['current'] = $index->numDocs(); } else { $status['current'] = 0; } WPSearch_Benchmark::stop($timer); return (object) $status; }