From 735ad1242efd8ebb1b9758b24277ef0734edd1ed Mon Sep 17 00:00:00 2001 From: Alexander Vlasov Date: Tue, 15 May 2018 09:38:41 +0300 Subject: [PATCH] Detect if APC is enabled when trying to use APC storage. --- src/Prometheus/Storage/APC.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Prometheus/Storage/APC.php b/src/Prometheus/Storage/APC.php index b608e49..2c2de32 100644 --- a/src/Prometheus/Storage/APC.php +++ b/src/Prometheus/Storage/APC.php @@ -4,6 +4,7 @@ namespace Prometheus\Storage; +use Prometheus\Exception\StorageException; use Prometheus\MetricFamilySamples; use RuntimeException; @@ -11,6 +12,16 @@ class APC implements Adapter { const PROMETHEUS_PREFIX = 'prom'; + /** + * @throws StorageException + */ + public function __construct() + { + if (!ini_get('apc.enabled') || ((php_sapi_name() == 'cli') && !ini_get('apc.enable_cli'))) { + throw new StorageException('APC is not enabled'); + } + } + /** * @return MetricFamilySamples[] */