Initial commit
This commit is contained in:
44
api-v1/src/index.php
Normal file
44
api-v1/src/index.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* API v1 Entry Point
|
||||
* Docker Container: php-fpm-v1
|
||||
* Endpoint: /api/v1/
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Проверяем подключение к PostgreSQL
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"pgsql:host=" . getenv('DB_HOST') . ";dbname=" . getenv('DB_NAME'),
|
||||
getenv('DB_USER'),
|
||||
getenv('DB_PASS')
|
||||
);
|
||||
$db_status = "connected";
|
||||
} catch (PDOException $e) {
|
||||
$db_status = "error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
// Проверяем подключение к Memcached
|
||||
try {
|
||||
$memcached = new Memcached();
|
||||
$memcached->addServer(getenv('MEMCACHED_HOST'), 11211);
|
||||
$memcached_status = $memcached->set('test_key', 'test_value', 10) ? "connected" : "error";
|
||||
} catch (Exception $e) {
|
||||
$memcached_status = "error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
// Формируем ответ
|
||||
$response = [
|
||||
'api_version' => 'v1',
|
||||
'status' => 'success',
|
||||
'timestamp' => time(),
|
||||
'services' => [
|
||||
'postgresql' => $db_status,
|
||||
'memcached' => $memcached_status,
|
||||
],
|
||||
'container' => gethostname(),
|
||||
'php_version' => PHP_VERSION,
|
||||
];
|
||||
|
||||
echo json_encode($response, JSON_PRETTY_PRINT);
|
||||
Reference in New Issue
Block a user