1. Go to this page and download the library: Download bylexus/php-prereqcheck library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bylexus / php-prereqcheck example snippets
# Include composer's autoload facility (recommended):
you best:
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";
}
# 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');