spatie/ssl-certificate
Retrieve and validate SSL/TLS certificates for any host in PHP. This package fetches certificate details like issuer, validity dates, and expiration status, making it easy to monitor domains and detect upcoming certificate issues in Laravel apps.
toArray() and createFromArray() enable custom validation logic or storage in databases (e.g., tracking certificate metadata).download()->forHost()) allows for flexible, readable configuration (e.g., custom ports, IP addresses, or socket contexts).CheckCertificatesJob) for batch validation of multiple hosts.openssl_x509_checkpurpose() or openssl_verify() in a wrapper class.CouldNotDownloadCertificate) are thrown but may need translation to Laravel’s HttpException or RuntimeException for consistency.:8443) or proxied environments (e.g., Cloudflare).*.example.com vs. example.com)?<30 days) trigger notifications (Slack, email)?Notification facade or a third-party tool (e.g., Sentry)?cache:table) to avoid repeated network calls?certificate_logs) for compliance audits?stream_socket_client() in unit tests to avoid flaky network tests.CertificateValidator) for dependency injection.certificate:check command for CLI validation (e.g., php artisan certificate:check example.com).ValidateCertificateMiddleware).CertificateExpired) to integrate with monitoring tools.openssl extension (enabled by default in Laravel).curl for alternative fetching methods (though the package uses stream_socket_client).app.example.com) to validate the integration.createForHostName() in a console command or scheduled job./api/* routes).schedule (e.g., ->command('certificate:check')->daily()).stream_socket_client(); use curl as a fallback.composer require spatie/ssl-certificate).app/Services/CertificateValidator.php) to wrap the package.isValid(), daysUntilExpiration()).certificate_validations table).spatie/laravel-slack-notification).Carbon or openssl functions (e.g., PHP 8.4’s implicit deprecations).stream_socket_client() errors (e.g., timeouts, DNS failures).openssl s_client for manual verification.isValid() returns false due to intermediate CA issues (not just expiration).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Certificate expires | Downtime if not renewed | Set alerts at 90/30 days before expiration. |
| Network unreachable | False "invalid" flag | Retry with exponential backoff; log failures. |
| Self-signed certificate | Validation fails | Whitelist known self-signed certs (e.g., staging environments). |
| CA trust check missing | Accepts untrusted certificates | Implement openssl_verify() in a wrapper class. |
| High latency in validation | Slow API responses | Cache results; offload to a background job. |
| Database/logging failures | No audit trail | Use Laravel’s failed() queue for critical validations. |
createForHostName(), `isHow can I help you explore Laravel packages today?