wunderio/drupal-ping 问题修复 & 功能扩展

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

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

wunderio/drupal-ping

Composer 安装命令:

composer require wunderio/drupal-ping

包简介

Drupal health check endpoint for load balancers

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

This script can be used for Drupal8 through Drupal11 uptime monitoring. It is not suitable for subsystem health-checks for things like container or load balancer.

Installation

  1. Add this to your composer.json:
{
    "extra": {
        "dropin-paths": {
            "web/": [
                "type:web-dropin",
                "package:wunderio/drupal-ping:_ping.php"
            ]
        }
    }
}
  1. Then install the composer package as usual with:
composer require wunderio/drupal-ping:^2
  1. Add _ping.php into the main project's .gitignore.

Changelog

See Releases.

Usage

  • Visit /_ping.php to get a system status
  • By using ?debug=token additional status check table and time profiling information is displayed
  • Find slow checks and checks errors in logs

Checks

Main database

User #1 record is fetched from the database.

Memcache

Assumes $settings['memcache']['servers'] presence in the settings.php.

Following statuses are issued:

  • disabled - No memcached servers defined in settings
  • success - All connections succeed
  • warning - At least one connection succeeds, at least one connection fails
  • error - All connections fail

Basic networking is used, no Memcached or Memcache class.

Redis

By using Redis class, connection is established to the server.

In settings.php following has to be defined:

  • $settings['redis.connection']['host']
  • $settings['redis.connection']['port']

This test works on both TCP and Unix Sockets. For the latter only host has to be defined as path.

Elasticsearch

In settings.php following has to be defined:

$settings['ping_elasticsearch_connections'] = [
  [
    'host' => 'hostname',
    'port' => 1234,
    'proto' => 'http', // http or https
    'severity' => 'warning', // warning or error
  ],
];

Elasticsearch check requires separate setting, because there are too many ways how Elasticsearch config can be defined in the settings.php file, depending on many factors.

The connection is establised by PHP curl, and then /_cluster/health is being visited. The check expects to get green status in the response.

Following statuses are issued:

  • disabled - No Elasticsearch servers defined in settings
  • success - All connections succeed
  • warning - At least one connection failed, and all failed connections have been configured with 'severity' = 'warning'
  • error - At least one connection failed, and at least one of the failed connections have been configured with 'severity' = 'error'

FS Scheme

Consists of 3 tests:

  • Check if a file can be created within the public filesystem.
  • Check if the test-file can be deleted from the public filesystem.
  • Check if there are any leftover test-files, and remove them.

Custom ping

If a site needs any custom checks, then just create _ping.custom.php. Use of $status->setName() and $status->set() to define the result. The PHP file does not need to contain functions, just plain PHP is enough. Check it out how other checks are created in the _ping.php.

Debug Mode

_ping.php can be accessed over the web. For example https://example.com/_ping.php. It can also be accessed from the shell cd /path/web ; php _ping.php. From the shell output the debug token can be attained. Then visit the ping again with https://example.com/_ping.php?debug=token.

The token is generated in one of the following ways. These methods are listed by precedance. If earlier fails (is empty), then next one is tried.

  • Drupal settings $settings['ping_token']
  • Environment variable PING_TOKEN
  • Md5 of the combination of environment variable values where the variable names matches regex /^(DB|ENVIRONMENT_NAME|GIT|PHP|PROJECT_NAME|S+MTP|VARNISH|WARDEN)/ - NB! This method assumes environment variable consistency between webserver and shell.
  • Md5 of Drupal settings $settings['hash_salt']
  • Md5 of the hostname

Ping Development & Testing

Setting up development environment

  1. Clone development and testing environment
  • git clone git@github.com:wunderio/drupal-project.git ~/projects/drupal-ping
  • Yes, save it as drupal-ping.
  1. cd drupal-ping/
  2. Clone the ping project itself
  • git clone git@github.com:wunderio/drupal-ping.git
  • Yes, save it as drupal-ping too, inside the folder of the same name. It is the actual repo we are going to work with.
  • Checkout or create your development branch.
  1. Link .lando.yml
  • rm -f .lando.yml - at the top-level folder, remove the Lando conf file.
  • ln drupal-ping/.lando.yml - link the Lando conf from the ping repo folder. Don't create this as a soft (-s) link because Lando would mount the project where the original file is. Therefore create the hard link which is indistinguishable for Lando.
  1. Link .lando/
  • rm -rf .lando - at the top-level folder, remove the Lando folder.
  • ln -s drupal-ping/.lando - link the Lando scripts folder from the ping repo folder.
  1. lando start
  2. Note that the Drupal install will mess up settings.php a bit, don't commit.
  3. https://ping.lndo.site/_ping.php
  4. lando scan
  5. lando test

Development commands

  • lando test - Execute phpunit tests
  • lando scan - Run coding standard checks

Maintainers

License

MIT

wunderio/drupal-ping 适用场景与选型建议

wunderio/drupal-ping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 248.52k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 06 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「drupal」 「ping」 「healthcheck」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 wunderio/drupal-ping 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 248.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 8
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-08