moinul / laravel-broken-link-scanner
Scan and report dead or broken links in your Laravel app
Requires
- php: ^8.0|^8.1|^8.2|^8.3|^8.4
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- maatwebsite/excel: ^3.1.50
- symfony/dom-crawler: ^6.0|^7.0
Requires (Dev)
- mockery/mockery: ^1.5|^1.6
- orchestra/testbench: ^7.8|^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.0
This package is auto-updated.
Last update: 2025-05-21 19:20:08 UTC
README
Laravel Broken Link Scanner
A Laravel package to scan and report dead or broken links in your Laravel application. It crawls your website and identifies any broken links (4xx/5xx status codes).
Features
- Asynchronous crawling with configurable concurrency
- Configurable crawl depth
- Export results to Excel
- Web interface to view and manage broken links
- Detailed progress reporting
- Database storage of broken links
- Support for Laravel 8.x, 9.x, 10.x, and 11.x
Installation
You can install the package via composer:
composer require moinul/laravel-broken-link-scanner
Configuration
- Publish the config file:
php artisan vendor:publish --provider="Moinul\LinkScanner\LinkScannerServiceProvider" --tag="config"
- Publish and run the migrations:
php artisan vendor:publish --provider="Moinul\LinkScanner\LinkScannerServiceProvider" --tag="migrations" php artisan migrate
- (Optional) Publish the views if you want to customize them:
php artisan vendor:publish --provider="Moinul\LinkScanner\LinkScannerServiceProvider" --tag="views"
Usage
Command Line
Scan your site for broken links:
# Scan using config start_url php artisan broken-links:scan # Scan specific URL php artisan broken-links:scan https://example.com # Scan with custom depth php artisan broken-links:scan --depth=3 # Clear old results before scanning php artisan broken-links:scan --clear-old # Show detailed progress php artisan broken-links:scan -v # Show very detailed progress php artisan broken-links:scan -vv # Show debug level information php artisan broken-links:scan -vvv
Web Interface
The package provides a web interface at /broken-links
to:
- View all broken links
- See status codes and reasons
- Export results to Excel
- Track when links were last checked
Configuration
You can configure the package by editing the config/broken-links.php
file:
return [ // The URL to start scanning from 'start_url' => env('APP_URL', 'http://localhost'), // How many links deep should the crawler go? Set to -1 for unlimited 'max_depth' => env('BROKEN_LINKS_MAX_DEPTH', 5), // How many URLs to check simultaneously 'concurrency' => env('BROKEN_LINKS_CONCURRENCY', 10), // How long to wait for each request (in seconds) 'timeout' => env('BROKEN_LINKS_TIMEOUT', 10), // The user agent string to use when making requests 'user_agent' => env('BROKEN_LINKS_USER_AGENT', 'Laravel Broken Link Scanner'), // The database table to store broken links in 'storage_table' => 'broken_links', ];
Programmatic Usage
You can also use the facade to scan programmatically:
use Moinul\LinkScanner\Facades\LinkScanner; // Scan using config start_url LinkScanner::scan(); // Scan specific URL LinkScanner::scan('https://example.com');
Events
The package dispatches the following events:
BrokenLinkFound
: When a broken link is discoveredScanCompleted
: When the scan is complete
Testing
composer test
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security related issues, please email engrminul@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.