PHP code example of hissezhaut / laravel-link-checker

1. Go to this page and download the library: Download hissezhaut/laravel-link-checker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hissezhaut / laravel-link-checker example snippets


// config/app.php
'providers' => [
    ...
    Spatie\LinkChecker\LinkCheckerServiceProvider::class,
];

// app/Console/Kernel.php
protected $commands = [
    ...
    \Spatie\LinkChecker\CheckLinksCommand::class,
];

return [

    /**
     * The base url of your app. Leave this empty to use
     * the url configured in config/app.php
     */
    'url' => '',

    /**
     * The profile determines which links need to be checked.
     */
    'default_profile' => Spatie\LinkChecker\CheckAllLinks::class,

    /**
     * The reporter determines what needs to be done when the
     * the crawler has visited a link.
     */
    'default_reporter' => Spatie\LinkChecker\Reporters\LogBrokenLinks::class,
    
    /**
     * To speed up the checking process we'll fire off requests concurrently. Here
     * you can change the amount of concurrent requests.
     */
    'concurrency' => 10

    /**
     *  Here you can specify configuration regarding the used reporters
     */
    'reporters' => [

        'mail' => [

            /**
             * The `from` address to be used by the mail reporter.
             */
            'from_address' => '',
            
            /**
             * The `to` address to be used by the mail reporter.
             */
            'to_address' => '',
        ],
    ],
];

// app/console/Kernel.php

protected function schedule(Schedule $schedule)
{
    ...
    $schedule->command('link-checker:run')->sundays();
}


interface CrawlProfile
{
    /**
     * Determine if the given url should be crawled.
     *
     * @param \Spatie\Crawler\Url $url
     *
     * @return bool
     */
    public function shouldCrawl(Url $url);
}

interface CrawlObserver
{
    /**
     * Called when the crawler will crawl the url.
     *
     * @param \Spatie\Crawler\Url $url
     */
    public function willCrawl(Url $url);

    /**
     * Called when the crawler has crawled the given url.
     *
     * @param \Spatie\Crawler\Url                      $url
     * @param \Psr\Http\Message\ResponseInterface|null $response
     */
    public function hasBeenCrawled(Url $url, $response);

    /**
     * Called when the crawl has ended.
     */
    public function finishedCrawling();
}
bash
php artisan vendor:publish --provider="Spatie\LinkChecker\LinkCheckerServiceProvider" --tag="config"
bash
php artisan link-checker:run