spatie/http-status-check
CLI tool to crawl a website and report HTTP status codes for every link. Scan internal and optionally external URLs, control concurrency for speed, and export failing (non-2xx/3xx) links to a file for quick auditing.
Installation
composer global require spatie/http-status-check
Ensure ~/.composer/vendor/bin is in your PATH or use the full path to the binary.
First Run
http-status-check https://example.com
This will crawl example.com, check all links, and output a table with URLs, status codes, and response times.
Where to Look First
http-status-check --help to explore all available flags.--format=json or --format=csv can be used for programmatic use.~/.config/spatie/http-status-check.php (auto-generated) for customizable defaults like:
max_depth (default: 1),ignore_status_codes (e.g., [404, 403]),user_agent,timeout.First Use Case
http-status-check https://your-site.com --max-depth=2 --ignore-status-codes=404
http-status-check https://example.com --format=csv > links_report.csv
Integrating into CI/CD
phpunit.xml or Makefile to run on deploy:
<php>
<env name="PATH" value="~/.composer/vendor/bin:$PATH"/>
</php>
<testsuite name="HTTP Status Checks">
<file>vendor/bin/http-status-check</file>
<arg value="https://your-site.com"/>
<arg value="--fail-on-status=500"/>
</testsuite>
5xx) are found:
http-status-check https://your-site.com --fail-on-status=500,404
Customizing Crawl Behavior
--exclude-paths to skip specific routes (e.g., /admin, /api):
http-status-check https://example.com --exclude-paths=/admin,/api
--follow-redirects=false to inspect intermediate responses.http-status-check https://example.com --delay=1000 # 1-second delay
Programmatic Use
jq for JSON parsing):
http-status-check https://example.com --format=json | jq '.[] | select(.status_code >= 400)'
Artisan::call() (if wrapped in a custom command).Monitoring Workflows
0 3 * * * /usr/bin/env php ~/.composer/vendor/bin/http-status-check https://your-site.com --format=csv --output=/var/log/link_checks.csv
link_checks table.spatie/laravel-backup to include link checks in backup validation.puppeteer or playwright to extract links before passing to http-status-check.--user-agent and --headers to mimic authenticated requests:
http-status-check https://example.com --headers="Authorization: Bearer token123"
Performance Issues
max_depth can be slow or hit rate limits.max_depth=1, then incrementally increase. Use --delay to throttle requests.http-status-check https://example.com --max-depth=2 --delay=500
False Positives/Negatives
--exclude-paths=/user/*) or mock responses in tests.Redirect Loops
--max-redirects=5 or exclude problematic domains.SSL/TLS Issues
--insecure to skip SSL verification (not recommended for production) or update your CA bundle.Output Parsing Quirks
--format=json for reliable parsing or sanitize CSV output with tools like mlr (Miller).Verbose Mode Enable debug output to inspect crawled URLs and responses:
http-status-check https://example.com --verbose
Crawling, Checking, and Skipping logs to identify why URLs are missed.Dry Runs
Use --dry-run to see which URLs will be checked without making requests:
http-status-check https://example.com --dry-run
Logging to File Redirect output for later analysis:
http-status-check https://example.com --verbose > debug.log 2>&1
Global Configuration
~/.config/spatie/http-status-check.php. Override defaults here for repeated use:
return [
'max_depth' => 2,
'ignore_status_codes' => [404, 410],
'user_agent' => 'MyAppLinkChecker/1.0',
];
Environment Variables
HTTP_STATUS_CHECK_TIMEOUT) can be set via environment variables, but check the source for supported vars.Custom Headers
Authorization or Cookie must be URL-encoded or passed via --headers:
http-status-check https://example.com --headers="Cookie: session_id=abc123"
Custom Status Code Handling
src/Checkers/StatusCodeChecker.php to add custom logic (e.g., treat 429 as a warning).Plugin System
5xx via webhooks).Integration with Laravel
http-status-check:
// app/Console/Commands/CheckSiteLinks.php
use Spatie\HttpStatusCheck\HttpStatusCheck;
class CheckSiteLinks extends Command {
protected $signature = 'site:check-links {url}';
public function handle() {
$checker = new HttpStatusCheck($this->argument('url'));
$results = $checker->check();
// Save to DB or log results
}
}
HttpStatusCheck class for programmatic access.Parallel Checks
parallel-lint or a custom script to split URLs across processes. The package itself does not support parallelism.How can I help you explore Laravel packages today?