enlight/pingping
Composer 安装命令:
composer require enlight/pingping
包简介
Easy PingPing API Connector for Laravel
README 文档
README
This composer package allows us to easily integrate PingPing APIs in your Laravel project.
What is PingPing ?
PingPing is the simplest uptime monitoring service in the world to get notified, when your website is down or your certificate becomes invalid. No more, no less.
Installation
Step 1: Composer
Firstly require this package using following command.
composer require enlight/pingping
Step 2: Service Provider (Optional)
This package support's auto discovery but for any reason you need to add ServiceProvider
into providers array manually then check follow steps below.
Open config/app.php and, within the providers array, append:
Enlight\PingPing\Providers\PingPingServiceProvider::class
This will bootstrap the package into Laravel.
Step 3: Set Up Environment
Check your .env file, and ensure that your PING_PING_API_TOKEN is set with valid token.
You can get the token from below link and make sure it is enabled.
You are all set to use it.
Step 4: Publish Configuration (Optional)
Optionally, You can publish configuration file, so you can modify defaults values.
To Publish Configuration Run
php artisan vendor:publish --provider="Enlight\PingPing\Providers\PingPingServiceProvider" --tag="config"
Exported config you can find in /config folder as pingping.php.
Usage
All methods and API calls will return Illuminate\Http\Client\Response instance. That mean's, you have access to
following methods.
$response->body() : string; $response->json() : array|mixed; $response->collect() : Illuminate\Support\Collection; $response->status() : int; $response->ok() : bool; $response->successful() : bool; $response->failed() : bool; $response->serverError() : bool; $response->clientError() : bool; $response->header($header) : string; $response->headers() : array;
Retrieve all websites (monitors)
use Enlight\PingPing\Client; public function index(Client $client) { $response = $client->monitors(); if ($response->failed()) { return $response->json(); } return $response->json(); }
Retrieve a specific website (monitor)
use Enlight\PingPing\Client; public function show($id, Client $client) { $response = $client->monitors((int) $id); if ($response->failed()) { return $response->json(); } return $response->json(); }
Retrieve statistics from a specific website (monitor)
use Enlight\PingPing\Client; use Enlight\PingPing\Exceptions\MonitorIDRequiredException; /** * @throws MonitorIDRequiredException */ public function show($id, Client $client) { $response = $client->statistics((int) $id); if ($response->failed()) { return $response->json(); } return $response->json(); }
Create a website (monitor)
use Enlight\PingPing\Client; use Enlight\PingPing\Exceptions\ValidUrlRequiredException; /** * @throws ValidUrlRequiredException */ public function store(Client $client) { $url = 'https://my-cool-website.test'; $response = $client->createMonitor($url); if ($response->failed()) { return $response->json(); } return $response->json(); }
Update a website (monitor)
use Enlight\PingPing\Client; use Enlight\PingPing\Exceptions\AliasRequiredException; use Enlight\PingPing\Exceptions\ValidUrlRequiredException; use Enlight\PingPing\Exceptions\MonitorIDRequiredException; /** * @throws AliasRequiredException * @throws ValidUrlRequiredException * @throws MonitorIDRequiredException */ public function update($id, Client $client) { $url = 'https://my-cool-website2.test'; $alias = 'My cool website2'; $response = $client->updateMonitor((int) $id, $url, $alias); if ($response->failed()) { return $response->json(); } return $response->json(); }
Delete a website (monitor)
use Enlight\PingPing\Client; use Enlight\PingPing\Exceptions\MonitorIDRequiredException; /** * @throws MonitorIDRequiredException */ public function destroy($id, Client $client) { $response = $client->deleteMonitor((int) $id); if ($response->failed()) { return $response->json(); } return $response->json(); }
Finally, your updated controllers might look like this now.
<?php declare(strict_types=1); namespace App\Http\Controllers; use Enlight\PingPing\Client; use Enlight\PingPing\Exceptions\AliasRequiredException; use Enlight\PingPing\Exceptions\ValidUrlRequiredException; use Enlight\PingPing\Exceptions\MonitorIDRequiredException; class MonitorController extends Controller { /** @var Client */ private $client; public function __construct(Client $client) { $this->client = $client; } public function index() { $response = $this->client->monitors(); if ($response->failed()) { return $response->json(); } return $response->json(); } public function show($id) { $response = $this->client->monitors((int) $id); if ($response->failed()) { return $response->json(); } return $response->json(); } /** * @throws ValidUrlRequiredException */ public function store() { $url = 'https://my-cool-website.test'; $response = $this->client->createMonitor($url); if ($response->failed()) { return $response->json(); } return $response->json(); } /** * @throws AliasRequiredException * @throws ValidUrlRequiredException * @throws MonitorIDRequiredException */ public function update($id) { $url = 'https://my-cool-website2.test'; $alias = 'My cool website2'; $response = $this->client->updateMonitor((int) $id, $url, $alias); if ($response->failed()) { return $response->json(); } return $response->json(); } /** * @throws MonitorIDRequiredException */ public function destroy($id) { $response = $this->client->deleteMonitor((int) $id); if ($response->failed()) { return $response->json(); } return $response->json(); } }
<?php declare(strict_types=1); namespace App\Http\Controllers; use Enlight\PingPing\Client; use Enlight\PingPing\Exceptions\MonitorIDRequiredException; class StatisticsController extends Controller { /** * @throws MonitorIDRequiredException */ public function show($id, Client $client) { $response = $client->statistics((int) $id); if ($response->failed()) { return $response->json(); } return $response->json(); } }
Contributors
This package is inspired by the Steve's blog post on Working with third party services in Laravel . I highly recommend you to read it.
Thank You :)
Happy Coding.
enlight/pingping 适用场景与选型建议
enlight/pingping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 15, 最近一次更新时间为 2021 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「pingping」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 enlight/pingping 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 enlight/pingping 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 enlight/pingping 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
A PingPing tile for Laravel Dashboard
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
Laravel package for Accurate Online API integration.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
统计信息
- 总下载量: 137
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-30