Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
health_check.php
Go to the documentation of this file.
1 <?php
8 
9 register_shutdown_function("fatalErrorHandler");
10 
11 try {
12  require __DIR__ . '/../app/bootstrap.php';
18  $deploymentConfig = $objectManager->get(\Magento\Framework\App\DeploymentConfig::class);
20  $logger = $objectManager->get(\Psr\Log\LoggerInterface::class);
21 } catch (\Exception $e) {
22  http_response_code(500);
23  exit(1);
24 }
25 
26 // check mysql connectivity
27 foreach ($deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) as $connectionData) {
28  try {
30  $dbAdapter = $objectManager->create(
31  \Magento\Framework\DB\Adapter\Pdo\Mysql::class,
32  ['config' => $connectionData]
33  );
34  $dbAdapter->getConnection();
35  } catch (\Exception $e) {
36  http_response_code(500);
37  $logger->error("MySQL connection failed: " . $e->getMessage());
38  exit(1);
39  }
40 }
41 
42 // check cache storage availability
43 $cacheConfigs = $deploymentConfig->get(ConfigOptionsListConstants::KEY_CACHE_FRONTEND);
44 if ($cacheConfigs) {
45  foreach ($cacheConfigs as $cacheConfig) {
46  if (!isset($cacheConfig[ConfigOptionsListConstants::CONFIG_PATH_BACKEND]) ||
47  !isset($cacheConfig[ConfigOptionsListConstants::CONFIG_PATH_BACKEND_OPTIONS])) {
48  http_response_code(500);
49  $logger->error("Cache configuration is invalid");
50  exit(1);
51  }
52  $cacheBackendClass = $cacheConfig[ConfigOptionsListConstants::CONFIG_PATH_BACKEND];
53  try {
55  $backend = new $cacheBackendClass($cacheConfig[ConfigOptionsListConstants::CONFIG_PATH_BACKEND_OPTIONS]);
56  $backend->test('test_cache_id');
57  } catch (\Exception $e) {
58  http_response_code(500);
59  $logger->error("Cache storage is not accessible");
60  exit(1);
61  }
62  }
63 }
64 
71 {
72  $error = error_get_last();
73  if ($error !== null) {
74  http_response_code(500);
75  }
76 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$logger
$deploymentConfig
$objectManager
if($cacheConfigs) fatalErrorHandler()
exit
Definition: redirect.phtml:12
$objectManagerFactory
static createObjectManagerFactory($rootDir, array $initParams)
Definition: Bootstrap.php:149
const BP
Definition: autoload.php:14
catch(\Exception $e) foreach($deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) as $connectionData) $cacheConfigs