/** * Retrieve the appropriate EP_HOST * * Looks at the defined EP_HOST or a backup global should the defined host failed. * Priority is given to the EP_HOST constand with the backups only used when needed. * * @since 1.6 * * @global array $ep_backup_host array of backup hosts * * @param bool $force Whether to force a new lookup or not * @param bool $use_only_backups Forces the use of only the backup array, no others * * @return string|WP_Error the host to use or an error */ public function get_ep_host($force = false, $use_only_backups = false) { global $ep_backup_host; // Delete the transient if we want to force a new good host lookup if (true === $force) { delete_site_transient('ep_last_good_host'); } $last_good_host = get_site_transient('ep_last_good_host'); if ($last_good_host) { return $last_good_host; } // If nothing is defined just return an error if (!defined('EP_HOST') && !$ep_backup_host) { return new WP_Error('elasticpress', __('No running host available.', 'elasticpress')); } $hosts = array(); if (defined('EP_HOST') && false === $use_only_backups) { $hosts[] = EP_HOST; } // If no backups are defined just return the host if ($ep_backup_host && is_array($ep_backup_host)) { $hosts = array_merge($hosts, $ep_backup_host); } foreach ($hosts as $host) { if (true === ep_elasticsearch_alive($host)) { set_site_transient('ep_last_good_host', $host, apply_filters('ep_last_good_host_timeout', 3600)); return $host; } } return new WP_Error('elasticpress', __('No running host available.', 'elasticpress')); }
/** * Provide better error messaging for common connection errors * * @since 0.9.3 */ private function _connect_check() { if (!defined('EP_HOST')) { WP_CLI::error(__('EP_HOST is not defined! Check wp-config.php', 'elasticpress')); } if (false === ep_elasticsearch_alive()) { WP_CLI::error(__('Unable to reach Elasticsearch Server! Check that service is running.', 'elasticpress')); } }
/** * Provide better error messaging for common connection errors * * @since 0.9.3 */ private function _connect_check() { $ep_server_url = ep_get_server_url(); if (!isset($ep_server_url)) { \WP_CLI::error(__('The Elasticsearch server URL is not defined! You should be calling "set-host", at least.', 'elasticpress')); } if (false === ep_elasticsearch_alive()) { \WP_CLI::error(__('Unable to reach Elasticsearch Server! Check that service is running.', 'elasticpress')); } }