PHPackages                             bylexus/php-prereqcheck - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bylexus/php-prereqcheck

ActiveLibrary

bylexus/php-prereqcheck
=======================

Helper class to create Prerequisite Check scripts for your software packages

0.2.1(10y ago)68.2k↓50%1copyrightPHPPHP &gt;=5.3.0

Since Apr 5Pushed 10y ago3 watchersCompare

[ Source](https://github.com/bylexus/php-prereqcheck)[ Packagist](https://packagist.org/packages/bylexus/php-prereqcheck)[ Docs](https://github.com/bylexus/php-prereqcheck)[ RSS](/packages/bylexus-php-prereqcheck/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (1)

[![Build Status](https://camo.githubusercontent.com/d2695a15d8594ca976afb2d8ee3f487c2150321e24f4208377ff2f7349f0ae99/68747470733a2f2f7472617669732d63692e6f72672f62796c657875732f7068702d707265726571636865636b2e737667)](https://travis-ci.org/bylexus/php-prereqcheck)

php-prereqcheck
===============

[](#php-prereqcheck)

Helper class to create Prerequisite Checks. It allows you to easily create a Prerequisite Check Script for your project, e.g. matching (php) version, installed extensions, settings etc. It also allows you to write your own checks to implement individual checks.

Features
--------

[](#features)

- Simple to use API to create own prerequisite scripts / checks
- Console, Web or silent (programmatic) output
- Builtin-checks:
    - php version check
    - php ini settings check
    - php extension checks
    - PDO DB connection check
    - dir writable check
- Extensible: Write your own Check classes easily

Planned features
----------------

[](#planned-features)

- Output renderers to customize output
- more built-in checks like http service availability, internet access, ...

Installation using composer
---------------------------

[](#installation-using-composer)

Because this is a "zero" version (0.x.y), composer needs some hints to install this package:

`composer.json`:

```
{
    "minimum-stability": "dev"
}
```

then:

```
$ composer require bylexus/php-prereqcheck
```

or install it using the `--dev` flag:

```
$ composer require --dev bylexus/php-prereqcheck
```

Installation without composer
-----------------------------

[](#installation-without-composer)

Just clone the git repo:

```
git clone https://github.com/bylexus/php-prereqcheck.git
```

Then just require the `prereq-loader.php` file to setup the autoloader.

Sample usage
------------

[](#sample-usage)

For a working example, see `example-usage.php`.

```
# Include composer's autoload facility (recommended):
require_once('vendor/autoload.php');

# OR use the own internal autoloader, whatever fits you best:
require_once($here.'/prereq-loader.php');

$pc = new \Prereq\PrereqChecker();

# Check PHP version:
$pc->checkMandatory('php_version','>=','5.3.0');

# Check for installed PHP extensions:
$pc->checkMandatory('php_extension','gd');
$pc->checkMandatory('php_extension','mbstring');
$pc->checkMandatory('php_extension','pdo');

# Check for php.ini settings:
$pc->checkOptional('php_ini','display_errors','off','boolean');
$pc->checkOptional('php_ini','memory_limit','>=256MB','number');
$pc->checkOptional('php_ini','error_reporting',E_STRICT,'bit_enabled');
# check a php.ini string using a regular expression:
$pc->checkOptional('php_ini','date.timezone','/Europe\/.+/','string');

# Check if dir exists and is writable:
$pc->checkMandatory('dir_writable','/tmp/');

# Check if a PDO DB Connection could be established:
$pc->checkOptional('db_pdo_connection',array('dsn'=>'mysql:host=127.0.0.1','username'=>'test','password'=>'test'));

# Create own checks:
class FileExistsChecker extends \Prereq\PrereqCheck {
    public function check($filename = null) {
        $this->name = "File exists: {$filename}";
        if (file_exists($filename)) {
            $this->setSucceed();
        } else {
            $this->setFailed('File does not exists.');
        }
    }
}
$pc->registerCheck('file_exists','FileExistsChecker');
$pc->checkMandatory('file_exists','some_file.txt');

# Each check returns a CheckResult instance:
$res = $pc->checkMandatory('php_version','>=','5.3.0');
if ($res->success()) {
	echo "Yes, your PHP version is compliant.";
}

# did all the checks succeed?
if ($pc->didAllSucceed()) {
    echo "All tests succeeded!\n";
} else {
    echo "Some tests failed. Please check.\n";
}
```

Built-in Checks
---------------

[](#built-in-checks)

### php\_version

[](#php_version)

Checks if the actual PHP version matches a version comparison.

Example:

```
$pc->checkMandatory('php_version','>=','5.3.0');
```

### php\_extension

[](#php_extension)

Checks if the given PHP extension is available.

Example:

```
$pc->checkMandatory('php_extension','pdo');
```

### php\_ini

[](#php_ini)

Checks if a given PHP ini setting matches the criteria. Because it is not (always) possible to determine the type of value, a comparison function is needed in the config:

Example:

```
$pc->checkOptional('php_ini','date.timezone','Europe/Zurich','string');
$pc->checkOptional('php_ini','date.timezone','/Europe\/.+/','string');
$pc->checkOptional('php_ini','display_errors','off','boolean');
$pc->checkOptional('php_ini','error_reporting',E_STRICT,'bit_enabled');
$pc->checkOptional('php_ini','error_reporting',E_NOTICE,'bit_disabled');
$pc->checkOptional('php_ini','memory_limit','>=128M','number');
```

Possible comparison functions:

- boolean: Checks if the given value is true-ish or false-ish (e.g. 'Off' means false)
- string: exact string match (e.g. default\_timezone = 'Europe/Zurich'). If encapsulated in '/' (e.g. /search/), the string is taken as Perl Regular Expression.
- enabled: Checks if the given bit(s) are set in the ini value (e.g. checks if E\_WARNING is set in error\_reporting)
- bit\_disabled: Checks if the given bit(s) are NOT set in the ini value (e.g. checks if E\_NOTICE is disabled in error\_reporting)
- number: Checks a number value against a comparison, e.g. if memory\_limit is &gt;= 512m.

### dir\_writable

[](#dir_writable)

Checks if a given dir exists and is writable.

Example:

```
$pc->checkMandatory('dir_writable','/tmp/');
```

### db\_pdo\_connection

[](#db_pdo_connection)

Checks if a PDO connection to a database can be established.

Example:

```
$pc->checkOptional('db_pdo_connection',array('dsn'=>'mysql:host=127.0.0.1','username'=>'test','password'=>'test'));
```

*Note:*

The options array must contain the following keys:

- dsn: The PDO dsn
- username: The username to connect
- password. The password to use

Write your own checks
---------------------

[](#write-your-own-checks)

Writing your own checks is very simple. Just provide a `\Prereq\PrereqCheck` class and register it with the PrereqChecker. Then you can run the defined check:

```
# Define a class that extends PrereqCheck and implements the check() function:
class FileExistsChecker extends \Prereq\PrereqCheck {
    public function check($filename = null) {
        $this->name = "File exists: {$filename}";
        if (file_exists($filename)) {
        	# mark check as succeed (default, don't have to be called):
            $this->setSucceed();
        } else {
        	# mark check as failed, add a failure message:
            $this->setFailed('File does not exists.');
        }
    }
}

# Register check with the PrereqChecker:
$pc->registerCheck('file_exists','FileExistsChecker');

# Execute the check:
$pc->checkMandatory('file_exists','some_file.txt');
```

Prerequisite (yes, it can check itself :-) )
--------------------------------------------

[](#prerequisite-yes-it-can-check-itself---)

- PHP &gt;= 5.3.0

Version History
---------------

[](#version-history)

- 0.1.1 First release
- 0.2.0 Introduced Namespace `Prereq`, and make use of the Composer autoload facility. NOTE: This version is NO LONGER compatible with 0.1.1!
- 0.2.1 Fixes PHP ini number comparisons: -1 now counts as "unlimited" or max integer (e.g. to support `memory_limit = -1`)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Recently: every ~116 days

Total

6

Last Release

3961d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1824718?v=4)[Alexander Schenkel](/maintainers/bylexus)[@bylexus](https://github.com/bylexus)

---

Top Contributors

[![bylexus](https://avatars.githubusercontent.com/u/1824718?v=4)](https://github.com/bylexus "bylexus (22 commits)")

---

Tags

checksystemrequirementsprerequisite

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bylexus-php-prereqcheck/health.svg)

```
[![Health](https://phpackages.com/badges/bylexus-php-prereqcheck/health.svg)](https://phpackages.com/packages/bylexus-php-prereqcheck)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[overtrue/phplint

`phplint` is a tool that can speed up linting of php files by running several lint processes at once.

1.0k13.2M726](/packages/overtrue-phplint)[maglnet/composer-require-checker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

99810.9M671](/packages/maglnet-composer-require-checker)[liip/monitor-bundle

Liip Monitor Bundle

4728.7M16](/packages/liip-monitor-bundle)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19024.6M15](/packages/datadog-php-datadogstatsd)[linfo/linfo

App and library for easily parsing and displaying system information of the host, like network/torrents/cpu/memory/usb/pci/sound cards/filesystems/raid array/ipmi/etc.

3701.7M23](/packages/linfo-linfo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
