承接 chrisrhymes/link-checker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chrisrhymes/link-checker

Composer 安装命令:

composer require chrisrhymes/link-checker

包简介

A laravel package to check for broken links in database content

README 文档

README

A package that will check for broken links in the specified model's fields. It will check both URL fields and fields containing HTML.

Downloads Downloads

Contents

Getting Started

composer require chrisrhymes/link-checker

Migrate the database

php artisan migrate

Add the Trait to your models

Add the HasBrokenLinks trait to your model

<?php

namespace App\Models;

use ChrisRhymes\LinkChecker\Traits\HasBrokenLinks;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory, HasBrokenLinks;
}

Publish the config (optional)

By default, the timeout for link checks is set to 10 seconds. There are also settings for the rate limiting.

If you wish to change this then publish the configuration file and update the values.

php artisan vendor:publish --provider="ChrisRhymes\LinkChecker\ServiceProvider"

Usage

Then you can check if the model has broken links in the specified field(s).

use ChrisRhymes\LinkChecker\Jobs\CheckModelForBrokenLinks;
use ChrisRhymes\LinkChecker\Facades\LinkChecker;

$post = Post::first();

// Dispatch the job directly
CheckModelForBrokenLinks::dispatch($post, ['content', 'url']);

// Or using the facade
LinkChecker::checkForBrokenLinks($post, ['content', 'url']);

This will queue a job to get the links from the model, which will then queue a job to check each link it finds.

The job will record an entry in the database for broken links with an empty url, but will skip testing mailto or tel links.

You will then need to run the queue to run the checks.

php artisan queue:work

It checks the link using the Laravel Http client Http::get($link)->failed() and if it fails it is determined to be a broken link.

Any broken links will be stored in the broken_links table, with a polymorphic relationship back to the original model.

If an exception is thrown, such as a timeout, then an exception_message will also be recorded in the broken_links table.

$post = Post::first();

$post->brokenLinks; // A collection of broken links for the model

$post->brokenLinks[0]->broken_link; // The link that is broken
$post->brokenLinks[0]->exception_message; // The optional exception message

Relative links

If you have relative links within a html field in your model (that don't begin with 'http'), then you can pass a 3rd parameter as the base. The CheckModelForBrokenLinks job will prepend the base to the relative url before it is checked.

If your relative links don't begin with /, then ensure your base parameter has a trailing slash, 'http://example.com/'.

use ChrisRhymes\LinkChecker\Jobs\CheckModelForBrokenLinks;
use ChrisRhymes\LinkChecker\Facades\LinkChecker;

$post = Post::first();

// Dispatch the job directly
CheckModelForBrokenLinks::dispatch($post, ['content', 'url'], 'http://example.com');

// Or using the facade
LinkChecker::checkForBrokenLinks($post, ['content', 'url'], 'http://example.com');

Rate Limiting

In order to reduce the amount of requests sent to a domain at a time, this package has rate limiting enabled.

The configuration file allows you to set the rate_limit to set how many requests can be sent to a single domain within a minute. The default is set to 5, so adjust as required for your circumstances.

The configuration file also allows you to set the retry_until so the job will be retried until the time limit (in munites) is reached.

User Agent

To set a custom user agent for requests sent by the link checker, set the user_agent in the configuration file. For example 'user_agent' => 'my-user-agent',

The default value is link-checker.

Verify SSL

To disable verifying the SSL certificate of the link you are checking, publish the package configuration and then set 'verify' => false,.

This uses the HTTP client withOptions() to set the verify request option in Guzzle.

Skipping status codes

If you would like to skip specific status code responses from being reported, then you can add these to your config file.

For example, to skip recording 429 or 504 response codes, add the following.

// config/link-checker.php

    /**
     * Status codes to skip from reporting
     */
    'status_codes_to_skip' => [429, 504],

Tests

The tests are built with Pest.

Run the tests using either of the below commands.

vendor/bin/pest

// Or

composer test

chrisrhymes/link-checker 适用场景与选型建议

chrisrhymes/link-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.25k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2022 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 chrisrhymes/link-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 chrisrhymes/link-checker 我们能提供哪些服务?
定制开发 / 二次开发

基于 chrisrhymes/link-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-16