### Example Health Check Responses (JSON) Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Illustrates the JSON structure for successful and various failure scenarios in health checks. ```json [ { "name": "redis_check", "result": true, "message": "ok", "params": [] } ] ``` ```json [ { "name": "redis_check", "result": false, "message": "Invalid redis dsn definition.", "params": [] } ] ``` ```json [ { "name": "redis_check", "result": false, "message": "Connection refused", "params": [] } ] ``` -------------------------------- ### Configure Dockerfile HEALTHCHECK Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Dockerfile instructions for setting up automatic health checks for a PHP-FPM container, including default and custom endpoint examples. ```dockerfile FROM php:8.1-fpm # Install your application COPY . /var/www/html WORKDIR /var/www/html # Configure health check HEALTHCHECK --start-period=15s --interval=5s --timeout=3s --retries=3 \ CMD curl -f http://localhost/health || exit 1 # For custom endpoint HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=3 \ CMD curl -f http://localhost/api/health/check || exit 1 ``` -------------------------------- ### Create Custom Health Check Class in PHP Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt A PHP example demonstrating how to implement a custom health check for disk space using the CheckInterface. ```php path); $minBytes = $this->minFreeSpaceGB * 1024 * 1024 * 1024; if ($freeSpace === false) { return new Response( 'disk_space', false, 'Unable to determine disk space' ); } if ($freeSpace < $minBytes) { return new Response( 'disk_space', false, sprintf('Low disk space: %.2f GB free', $freeSpace / 1024 / 1024 / 1024), ['free_bytes' => $freeSpace, 'required_bytes' => $minBytes] ); } return new Response( 'disk_space', true, 'ok', ['free_bytes' => $freeSpace] ); } } ``` -------------------------------- ### Manage Symfony Recipes Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/UPGRADE-1.0.md These commands are used to manage Symfony recipes, which help keep your project's configuration files in sync with the latest versions provided by Symfony bundles. Use `composer recipes` to list available recipes and `composer recipes:install` to install or update a specific recipe. ```console $ composer recipes $ composer recipes symfony/framework-bundle $ composer recipes:install symfony/framework-bundle --force -v ``` -------------------------------- ### Install Bundle with Composer Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/README.md Installs the Symfony Health Check Bundle using Composer. This is the primary method for adding the bundle to your Symfony project. ```console composer require macpaw/symfony-health-check-bundle ``` -------------------------------- ### Health Check Endpoint Response Example Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Illustrates a typical JSON response from the health check endpoint when all configured checks pass, providing status, names, and messages for each check. ```bash curl -X GET http://localhost/health # Response (200 OK - all checks pass): [ { "name": "doctrine", "result": true, "message": "ok", "params": [] }, { "name": "doctrine_odm_check", "result": true, "message": "ok", "params": [] }, { "name": "redis_check", "result": true, "message": "ok", "params": [] }, { "name": "environment", "result": true, "message": "ok", "params": ["production"] }, { "name": "disk_space", "result": true, "message": "ok", "params": {"free_bytes": 53687091200} }, { "name": "external_api", "result": true, "message": "ok", "params": {"response_time_ms": 145} } ] ``` -------------------------------- ### GET /health - Environment Check Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Checks the application environment. Returns a 200 OK status with environment details. ```APIDOC ## GET /health ### Description Checks the application environment. Returns a 200 OK status with environment details. ### Method GET ### Endpoint /health ### Parameters #### Query Parameters None ### Request Example ```bash curl -X GET http://localhost/health ``` ### Response #### Success Response (200) - **name** (string) - The name of the check (e.g., "environment"). - **result** (boolean) - True if the check passed, false otherwise. - **message** (string) - A human-readable message about the check result. - **params** (array) - An array of parameters related to the check (e.g., the environment name). #### Response Example ```json [ { "name": "environment", "result": true, "message": "ok", "params": ["production"] } ] ``` ``` -------------------------------- ### Implement a Custom Health Check (PHP) Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/README.md Provides an example of how to create a custom health check by implementing the `CheckInterface`. The `check()` method should return a `Response` object indicating the status. ```php addHealthCheck(new StatusUpCheck()); $healthController->addHealthCheck(new DoctrineORMCheck($container)); // Set custom error code $healthController->setCustomResponseCode(503); // Execute checks $response = $healthController->check(); // Get response data $statusCode = $response->getStatusCode(); // 200 or 503 $content = json_decode($response->getContent(), true); foreach ($content as $check) { if (!$check['result']) { error_log(sprintf( 'Health check failed: %s - %s', $check['name'], $check['message'] )); } } ``` -------------------------------- ### Enable Symfony Health Check Bundle in Symfony Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt This PHP code demonstrates how to enable the Symfony Health Check Bundle within your Symfony application's configuration. This is typically done in the `config/bundles.php` file. ```php // config/bundles.php ['all' => true], // ... ]; ``` -------------------------------- ### Check Docker Container Health Status Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Bash commands to inspect the health status of running Docker containers and view detailed health check logs. ```bash # Check container health status docker ps # Shows health status: healthy, unhealthy, or starting # View health check logs docker inspect --format='{{json .State.Health}}' container_name ``` -------------------------------- ### Check Custom Health Check via Curl Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Command to test the custom disk space health check and its successful JSON response. ```bash curl -X GET http://localhost/health # Response (200 OK): [ { "name": "disk_space", "result": true, "message": "ok", "params": { "free_bytes": 53687091200 } } ] ``` -------------------------------- ### Override Default Endpoint Paths in Symfony Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt YAML configuration to customize the default URL paths for health and ping endpoints. ```yaml # config/routes/symfony_health_check.yaml health: path: /api/health/check methods: GET controller: SymfonyHealthCheckBundle\Controller\HealthController::check ping: path: /api/ping methods: GET controller: SymfonyHealthCheckBundle\Controller\PingController::check ``` -------------------------------- ### Redis Connection Health Check Configuration Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt This YAML configuration enables the Redis connection health check and specifies the Redis Data Source Name (DSN). Ensure the `symfony_health_check.redis_check` service is available and the provided `redis_dsn` is correct. ```yaml # config/packages/symfony_health_check.yaml symfony_health_check: health_checks: - id: symfony_health_check.redis_check redis_dsn: 'redis://localhost:6379' ``` -------------------------------- ### Enable Bundle in config/bundles.php Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/README.md Enables the Symfony Health Check Bundle by adding its class to the configuration file for applications not using Symfony Flex. This ensures the bundle is registered with the Symfony application. ```php // config/bundles.php ['all' => true], // ... ]; ``` -------------------------------- ### Redis Check Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Specific health check for validating the connection to a Redis instance. ```APIDOC ## Redis Check ### Description Validates the connection status to a Redis instance. ### Method GET ### Endpoint /health ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200 OK) - **name** (string) - "redis" - **result** (boolean) - true if the connection is successful. - **message** (string) - "ok" if successful. - **params** (array) - Empty array. #### Response Example (Success) ```json [ { "name": "redis", "result": true, "message": "ok", "params": [] } ] ``` #### Response Example (Failure) ```json [ { "name": "redis", "result": false, "message": "Could not connect to Redis.", "params": [] } ] ``` ``` -------------------------------- ### Update Bundle with All Dependencies Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/UPGRADE-1.0.md If dependency errors occur during the bundle update, this command can be used to update the specified bundle along with all its dependencies. This is useful for resolving complex dependency conflicts. ```console $ composer update "macpaw/symfony-health-check-bundle" --with-all-dependencies ``` -------------------------------- ### Configure Security for Health Check Endpoints Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/README.md Optionally configures security settings to allow anonymous access to the health check and ping endpoints. This is done by defining a new firewall in the security configuration. ```yaml # config/packages/security.yaml firewalls: healthcheck: pattern: ^/health security: false ping: pattern: ^/ping security: false ``` -------------------------------- ### Doctrine ODM MongoDB Connection Health Check Configuration Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt This YAML configuration enables the Doctrine ODM MongoDB connection health check. This requires the `symfony_health_check.doctrine_odm_check` service to be properly set up within your Symfony project. ```yaml # config/packages/symfony_health_check.yaml symfony_health_check: health_checks: - id: symfony_health_check.doctrine_odm_check ``` -------------------------------- ### Doctrine ORM Database Connection Health Check Configuration Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt This YAML configuration enables the Doctrine ORM database connection health check. Ensure the `symfony_health_check.doctrine_orm_check` service is correctly configured in your Symfony application. ```yaml # config/packages/symfony_health_check.yaml symfony_health_check: health_checks: - id: symfony_health_check.doctrine_orm_check ``` -------------------------------- ### Configure Custom Error Response Codes for Health Checks Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt This YAML configuration allows you to define custom HTTP status codes for error responses from the health and ping endpoints. `ping_error_response_code` and `health_error_response_code` can be set to specific integers. ```yaml # config/packages/symfony_health_check.yaml symfony_health_check: health_checks: - id: symfony_health_check.doctrine_orm_check ping_checks: - id: symfony_health_check.status_up_check ping_error_response_code: 500 health_error_response_code: 503 ``` -------------------------------- ### Doctrine ORM Check Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Specific health check for validating the database connection using Doctrine ORM. ```APIDOC ## Doctrine ORM Check ### Description Validates the database connection status when using Doctrine ORM. ### Method GET ### Endpoint /health ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200 OK) - **name** (string) - "doctrine" - **result** (boolean) - true if the connection is successful. - **message** (string) - "ok" if successful. - **params** (array) - Empty array. #### Response Example (Success) ```json [ { "name": "doctrine", "result": true, "message": "ok", "params": [] } ] ``` #### Response Example (Failure) ```json [ { "name": "doctrine", "result": false, "message": "Entity Manager Not Found.", "params": [] } ] ``` ``` -------------------------------- ### Register Custom Health Check in Configuration Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/README.md Adds a custom health check to the bundle's configuration by referencing its service ID. This allows the custom check to be included in the overall health check process. ```yaml symfony_health_check: health_checks: - id: symfony_health_check.doctrine_orm_check - id: custom_health_check // custom service check id ``` -------------------------------- ### Doctrine ODM Check Source: https://context7.com/macpaw/symfony-health-check-bundle/llms.txt Specific health check for validating the database connection using Doctrine ODM (for NoSQL databases like MongoDB). ```APIDOC ## Doctrine ODM Check ### Description Validates the database connection status when using Doctrine ODM. ### Method GET ### Endpoint /health ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200 OK) - **name** (string) - "doctrine_odm_check" - **result** (boolean) - true if the connection is successful. - **message** (string) - "ok" if successful. - **params** (array) - Empty array. #### Response Example (Success) ```json [ { "name": "doctrine_odm_check", "result": true, "message": "ok", "params": [] } ] ``` #### Response Example (Failure) ```json [ { "name": "doctrine_odm_check", "result": false, "message": "Document Manager Not Found.", "params": [] } ] ``` ``` -------------------------------- ### Update Security Configuration for Health Check Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/UPGRADE-1.0.md This snippet illustrates the modification needed in `config/packages/security.yaml` to accommodate the new `/ping` route for health checks. It adds a new firewall entry for the ping route. ```yaml firewalls: healthcheck: pattern: ^/health security: false ping: pattern: ^/ping security: false ``` -------------------------------- ### Update Symfony Health Check Configuration Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/UPGRADE-1.0.md This snippet shows the changes required in the `config/packages/symfony_health_check.yaml` file for upgrading the bundle. It includes adding `ping_checks` section. ```yaml symfony_health_check: health_checks: - id: symfony_health_check.doctrine_check ping_checks: - id: symfony_health_check.status_up_check ``` -------------------------------- ### Update Custom Health Check Return Type Source: https://github.com/macpaw/symfony-health-check-bundle/blob/develop/UPGRADE-1.0.md This code demonstrates how to update a custom health check class to return a `Response` object instead of an array. This change is necessary to align with the updated bundle's requirements for health check responses. ```php use SymfonyHealthCheckBundleDtoResponse; class StatusUpCheck implements CheckInterface { public function check(): Response { return new Response('status', true, 'up'); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.