Installation:
composer require atoolo/runtime-check-bundle
Add to config/bundles.php:
return [
// ...
Atoolo\RuntimeCheckBundle\AtooloRuntimeCheckBundle::class => ['all' => true],
];
First Use Case: Run a basic runtime check via CLI:
php bin/console runtime:check
This triggers a full environment validation (PHP version, extensions, FPM, etc.).
Quick Check in Code:
Inject the RuntimeCheckService and run checks programmatically:
use Atoolo\RuntimeCheckBundle\Service\RuntimeCheckService;
public function __construct(private RuntimeCheckService $runtimeCheck)
{}
public function checkEnvironment()
{
$result = $this->runtimeCheck->checkAll();
if (!$result->isValid()) {
throw new \RuntimeException('Environment misconfiguration detected.');
}
}
php bin/console list atoolo:runtime-check
config/packages/atoolo_runtime_check.yaml (auto-generated).Pre-Deployment Checks: Integrate with CI/CD pipelines (e.g., GitHub Actions) to block deployments:
# .github/workflows/deploy.yml
jobs:
check-environment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: php bin/console runtime:check --fail-on-error
Dynamic Validation in Controllers: Use middleware to validate runtime before serving requests:
// src/Kernel.php
protected function build(RequestContext $requestContext): void
{
$this->addRuntimeCheckMiddleware();
}
private function addRuntimeCheckMiddleware(): void
{
$this->middleware(function (Request $request, Closure $next) {
$runtimeCheck = $this->container->get(RuntimeCheckService::class);
if (!$runtimeCheck->checkAll()->isValid()) {
abort(503, 'Environment not ready.');
}
return $next($request);
});
}
Custom Checks: Extend the bundle’s check system by creating a custom validator:
// src/Validator/CustomCheckValidator.php
use Atoolo\RuntimeCheckBundle\Validator\RuntimeCheckValidatorInterface;
class CustomCheckValidator implements RuntimeCheckValidatorInterface
{
public function validate(): bool
{
return file_exists('/custom/required/file');
}
public function getName(): string
{
return 'Custom File Check';
}
}
Register in config/packages/atoolo_runtime_check.yaml:
atoolo_runtime_check:
validators:
- Atoolo\RuntimeCheckBundle\Validator\PhpVersionValidator
- App\Validator\CustomCheckValidator
Scheduled Checks: Use Symfony’s scheduler to run periodic validations (e.g., nightly):
# config/packages/messenger.yaml
framework:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
routing:
'Atoolo\RuntimeCheckBundle\Message\RuntimeCheckMessage': async
Dispatch a message:
$this->messageBus->dispatch(new RuntimeCheckMessage());
config/packages/monolog.yaml).--fail-on-error flag in CLI for strict validation.$this->runtimeCheck->checkAll(true); // Cache results
FPM Socket Paths:
/run/php-fpm.socket). On SUSE, use the custom path:
# config/packages/atoolo_runtime_check.yaml
atoolo_runtime_check:
fpm_socket_path: '/var/run/php-fpm.socket' # Override if needed
ls -la /run/php-fpm.socket
PHP Version Mismatch:
ext-posix and opcache are enabled:
php -m | grep -E 'posix|opcache'
php.ini:
extension=posix
opcache.enable=1
Lock Contention:
LockStore (default: file). In shared environments, configure a robust store:
# config/packages/atoolo_runtime_check.yaml
atoolo_runtime_check:
lock_store: 'symfony.lock.store.redis'
Custom Validators:
false gracefully (e.g., log warnings instead of throwing exceptions).$validator = $this->createMock(RuntimeCheckValidatorInterface::class);
$validator->method('validate')->willReturn(false);
$validator->method('getName')->willReturn('Test Validator');
$this->runtimeCheck->addValidator($validator);
php bin/console runtime:check --verbose
tail -f var/log/dev.log | grep "RuntimeCheck"
php bin/console runtime:check php-version
php bin/console runtime:check fpm
Override Default Checks:
Disable built-in validators in config/packages/atoolo_runtime_check.yaml:
atoolo_runtime_check:
enabled_validators: ['php_version', 'fpm'] # Whitelist
Custom Error Responses:
Extend the RuntimeCheckResult class to add metadata:
// src/Result/CustomRuntimeCheckResult.php
class CustomRuntimeCheckResult extends RuntimeCheckResult
{
public function addMetadata(string $key, mixed $value): void
{
$this->metadata[$key] = $value;
}
}
Bind the service in services.yaml:
services:
Atoolo\RuntimeCheckBundle\Service\RuntimeCheckService:
arguments:
$resultClass: App\Result\CustomRuntimeCheckResult
Webhook Notifications: Dispatch events when checks fail:
// src/EventListener/RuntimeCheckListener.php
use Atoolo\RuntimeCheckBundle\Event\RuntimeCheckFailedEvent;
class RuntimeCheckListener
{
public function onCheckFailed(RuntimeCheckFailedEvent $event)
{
// Send Slack/email alert
}
}
Register in services.yaml:
services:
App\EventListener\RuntimeCheckListener:
tags:
- { name: 'kernel.event_listener', event: 'runtime_check.failed', method: 'onCheckFailed' }
RUNTIME_CHECK_ to override defaults:
export RUNTIME_CHECK_FPM_SOCKET_PATH=/custom/path.socket
symfony/scheduler is installed if using scheduled checks (added in Symfony 6.3+).docker-compose.yml:
services:
php:
volumes:
- /run/php-fpm.socket:/run/php-fpm.socket
How can I help you explore Laravel packages today?