cytopia/check_php
Composer 安装命令:
composer require cytopia/check_php
包简介
Nagios or Icinga plugin to check for php startup errors.
README 文档
README
check_php is a POSIX compliant nagios plugin that will check for PHP startup errors (-s), missing PHP modules (-m), misconfigured directives in php.ini (-c) and for available PHP updates (-u). This plugin supports performance data (error and warning counts over time) and long output (exact detail about all problems).
Nagios Configuration | Icinga2 Configuration | Usage | Examples | License | Contributors | Awesome
![]() |
Find more plugins at Awesome Nagios |
|---|---|
![]() |
Find more plugins at Icinga Exchange |
![]() |
Find more plugins at Nagios Exchange |
Requirements
| Program | Required | Description |
|---|---|---|
| bourne shell (sh) | yes | The whole script is written in pure bourne shell (sh) and is 100% Posix compliant |
| check_by_ssh | yes | This nagios plugin is used as a wrapper to check on remote hosts |
| wget, curl or fetch | Optional | Either one of them is required if you want to check against PHP updates. (-u) |
Features
- Check for PHP startup errors
- Check for PHP updates (inside minor versions and patch levels)
- Check for missing PHP modules
- Check for blacklisted PHP modules and throw err/warn if they are compiled in
- Check for expected php.ini config directives (e.g.: date.timezone must be "Europe/Berlin", etc)
- Each check can specify its own severity (warning or error)
Motivation
If you have to take care about many servers which have PHP installed you can use this plugin to make sure that all servers or all groups of server use the same configuration with the same compiled modules and are always up to date.
1. Nagios Configuration
1.1 Command definition
In order to check php on remote servers you will need to make use of check_by_ssh.
name: check_by_ssh_php command: $USER1$/check_by_ssh -H $HOSTADDRESS$ -t 60 -l "$USER17$" -C "$USER22$/check_php $ARG1$"
1.2 Service definition
In the above command definition there is only one argument variable assigned to check_php: $ARG1. So you can easily assign all required arguments to this single variable in the service definition:
check command: check_by_ssh_php
$ARG1$: -s e -u w -m curl e -m gettext e -m openssl e -m json e
2. Icinga2 Configuration
2.1 Command definition
/* * Check PHP health */ object CheckCommand "php" { import "plugin-check-command" command = [ PluginDir + "/check_php" ] arguments = { "-s" = { value = "$php_startup$" description = "Check for PHP startup errors and display warning or error if any exists. Allowed values are 'w' for warnings and 'e' for critical errors." } "-u" = { value = "$php_updates$" description = "Check for updated PHP version online. Allowed values are 'w' for warnings and 'e' for critical errors. This check requires wget, curl or fetch." } "-p" = { value = "$php_binary$" description = "Optional path to PHP binary. This argument allows to define a certain PHP binary to be checked. If none is defined, the default PHP version will be used." } "-d" = { value = "$php_delimiter$" description = "Delimiter for multi-value arguments." } "-m" = { value = "$php_modules$" description = "Check for required modules." repeat_key = true } "-b" = { value = "$php_blacklist$" description = "Check for blacklisted modules." repeat_key = true } "-c" = { value = "$php_config$" description = "Check PHP setting directives that diverge from the given default value." repeat_key = true } "-v" = { set_if = "$php_verbose$" description = "Enable verbose mode." } } }
2.2 Service definition example (using apply)
/* * PHP Health */ apply Service "php-" for (php => config in host.vars.php) { check_command = "php" // Assuming your PHP setup doesn't change too often, we don't // bother to check twice a day only. check_interval = 12h display_name = "PHP " + php notes = "Checks currently installed PHP " + php + " health." // Service variables from php definition. vars += config vars.php_delimiter = "|" if ( config.php_modules ) { vars.php_modules = [] for (key => value in config.php_modules) { vars.php_modules += [ key + vars.php_delimiter + value ] } } if ( config.php_blacklist ) { vars.php_blacklist = [] for (key => value in config.php_blacklist) { vars.php_blacklist += [ key + vars.php_delimiter + value ] } } if ( config.php_config ) { vars.php_config = [] for (key => value in config.php_config) { vars.php_config += [ key + vars.php_delimiter + value["default"] + vars.php_delimiter + value["severity"] ] } } // Application rules. assign where host.name = NodeName && host.vars.php }
2.3 Host object definition
object Host "node.example.com" { // Other settings. vars.php[ "7.1" ] = { php_binary = "/opt/php/7.1/bin/php" php_updates = "w" php_startup = "e" php_modules = { intl = "w" mbstring = "w" soap = "w" apcu = "w" memcached = "w" geoip = "w" mongodb = "w" imagick = "w" redis = "w" openssl = "w" xml = "w" json = "w" curl = "w" } php_blacklist = { mcrypt = "w" } php_config = { "date.timezone" = { "default" = "Europe/Berlin" "severity" = "w" } } } }
3. Usage
Each argument allows you to specify which severity should be triggered (<w|e>), where w triggers a warning and e triggers an error.
Arguments that can be used multiple times (-m and -c) can of course use different severities each time. All severities will be aggregated and the highest severity (error > warning) will determine the final state.
Usage: check_php [-s <w|e>] [-u <w|e>] [-m <module> <w|e>] [-b <module> <w|e> [-c <conf> <val> <w|e>] [-p <path>] [-d <delimiter>] [-v] check_php -h check_php -V Nagios plugin that will check if PHP exists, for PHP startup errors, missing modules, misconfigured directives and available updates. -s <w|e> [single] Check for PHP startup errors and display nagios warning or error if any exists. Warning: -s w Error: -s e -u <w|e> [single] Check for updated PHP version online. (requires wget, curl or fetch) Will only check for patch updates and will not notify if your current version PHP 5.5 and there is already PHP 5.6 out there. -m <module> <w|e> [multiple] Require compiled PHP module and display nagios warning/error if the module was not compiled against PHP. Use multiple times to check against multiple modules. Example: -m "mysql" w -m "mysqli" e -b <module> <w|e> [multiple] Check PHP for modules that should not be compiled in and display nagios warning/error if the module is compiled against PHP. Use multiple times to check for multiple blacklisted modules. Example: -b "imagick" w -b "tidy" e -c <conf> <val> <w|e> [multiple] Check for misconfigured directives in php.ini and display nagios warning/error if the configuration does not match. Use multiple times to check against multiple configurations. Example: -c "date.timezone" "Europe/Berlin" e -p <path> [optional] Define the path to the PHP binary that shall be used. If no value is given, the current user's default PHP version will be checked. Example: -p "/usr/bin/php" -d <delimiter> [optional] Delimiter used to concatenate arguments of the above options that require multiple values. Example: -d "|" -m "mysql|w" -b "mcrypt|w" -c "date.timezone|Europe/Berlin|e" -v Be verbose (Show PHP Version and Zend Engine Version) -h Display help -V Display version
4. Examples
Checking against prefered timezone and compiled module mysql
$ check_php -c "date.timezone" "Europe/Berlin" e -m mysql e [ERR] PHP 5.6.16 has errors: Missing module(s) | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; [CRITICAL] Module: "mysql" not available [OK] Config "date.timezone" = "Europe/Berlin"
Checking for PHP startup errors
$ check_php -s w [WARN] PHP 5.6.16 has warning: Startup errors | 'OK'=0;;;; 'Errors'=0;;;; 'Warnings'=1;;;; 'Unknown'=0;;;; [WARNING] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226/test' - dlopen(/usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226/test, 9): image not found in Unknown on line 0
Combine multiple module checks
$ check_php -m mysql e -m mysqli w -m mbstring w [OK] PHP 5.6.16 is healthy | 'OK'=1;;;; 'Errors'=0;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; [OK] Module: "mysql" available [OK] Module: "mysqli" available [OK] Module: "mbstring" available
Checking for PHP Updates (OK)
$ check_php -u e [OK] PHP 5.6.16 is healthy | 'OK'=1;;;; 'Errors'=0;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; [OK] No PHP startup errors [OK] PHP Version 5.6.14 up to date.
Checking for PHP Updates (Updates available)
$ check_php -u e [ERR] PHP 5.6.13 has errors: Updates available | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=-;;;; 'Unknown'=0;;;; [OK] No PHP startup errors [CRITICAL] PHP Version 5.6.13 too old. Latest: 5.6.14.
Checking for PHP Updates (Able to differentiate between PHP 5.4, 5.5 and 5.6)
$ check_php -u e [ERR] PHP 5.5.1 has errors: Updates available | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; [OK] No PHP startup errors [CRITICAL] PHP Version 5.5.1 too old. Latest: 5.5.30.
A lot of options combined
$ check_php -s w -m mysql e -m mbstring e -m xml e -c date.timezone 'Europe/Berlin' e -c session.cookie_secure "On" e -u e -v [ERR] PHP 5.6.14 has errors: Wrong config | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; [OK] No PHP startup errors [OK] PHP Version 5.6.14 up to date. [OK] Module: "mysql" available [OK] Module: "mbstring" available [OK] Module: "xml" available [OK] Config "date.timezone" = "Europe/Berlin" [CRITICAL] Config "session.cookie_secure" = "Off", excpected: "On" PHP 5.6.14 Zend Engine v2.6.0
5. License
6. Contributors
7. Awesome
cytopia/check_php 适用场景与选型建议
cytopia/check_php 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 1.46k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2015 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「nagios」 「php-error」 「icinga」 「nagios-plugin」 「icinga2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cytopia/check_php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cytopia/check_php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cytopia/check_php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Full featured error logging module for ZF2/ZF3 application
Nagios plugin to verify a git repository.
This nagios plugin will check if your drupal site has issues (security updates, updates[optional], outstanding db updates, other problems).
Simple monitoring tooling and Symfony bundle
Nagios configuration parser
Provides Icinga check and notification commands.
统计信息
- 总下载量: 1.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-23


