lfischer/internet-available 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lfischer/internet-available

Composer 安装命令:

composer require lfischer/internet-available

包简介

A small component to check if the internet is currently available / accessible

README 文档

README

A small component to check if the internet is accessible. Original idea by Stackoverflow #4860365. This project adheres to Semantic Versioning.

Usage

The very basic usage (with default parameters) looks like this:

$available = \lfischer\internet\Internet::available();

But of course there are some options you can provide to handle the responses as you need them:

use \lfischer\internet\Internet;
use \lfischer\internet\InternetException;
use \lfischer\internet\InternetProblemException;

// Check the availability by connecting to Google on port 80.
$available = (new Internet('www.google.com', 80))->check();

//
try {
    $internet = new Internet(
        'www.google.com', 
        80, 
        Internet::EXCEPTION_ON_UNAVAILABILITY + Internet::PROBLEM_AS_EXCEPTION
    );

    $available = $internet->check();
} catch (InternetException $e) {
    // The internet is not available.
    $internet->getErrorString();
    $internet->getErrorNumber();
    $e->getMessage();
} catch (InternetProblemException $e) {
    // There was a problem while checking the availability.
     $internet->getErrorString();
     $internet->getErrorNumber();
     $e->getMessage();
 }

Options

You can pass some options to change the behaviour in case of problems.

  • Internet::EXCEPTION_ON_UNAVAILABILITY
    Will throw an InternetException exception if the internet is unavailable (instead of returning false).
  • Internet::PROBLEM_AS_EXCEPTION
    Will throw an InternetProblemException exception if the internet availability could not be checked due to a problem (instead of returning false).
  • Internet::PROBLEM_AS_TRUE
    Will return true in case of a problem during the availability check since you'd like to assume something else went wrong.

Static code analysis and code style

The code is being statically analyzed with the help of vimeo/psalm. The PSR2 code style will be checked/applied with the help of friendsofphp/php-cs-fixer.

统计信息

  • 总下载量: 63
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固