<?php
class CheckPlateform
{
//All values if not explicit
//PHP version
const MIN_ALLOWED_PHP_VERSION = "5.0.0";
const MAX_ALLOWED_PHP_VERSION = null;//excluded
//Memory
const MIN_ALLOWED_MEMORY_CLI = 512;//In M
const MAX_ALLOWED_MEMORY_CLI = null;//In M
const MIN_ALLOWED_MEMORY_WEB = 128;//In M
const MAX_ALLOWED_MEMORY_WEB = null;//In M
//Execution time
const MIN_ALLOWED_EXECUTION_TIME_CLI = 30;//in s
const MAX_ALLOWED_EXECUTION_TIME_CLI = null;//in s
const MIN_ALLOWED_EXECUTION_TIME_WEB = 30;//in s
const MAX_ALLOWED_EXECUTION_TIME_WEB = null;//in s
//Internet access
const CHECK_INTERNET_ACCESS = true;//or false
//MySql
const MYSQL_HOST = 'localhost';//or null
const MIN_ALLOWED_MYSQL_VERSION = "5.5.0";
const MAX_ALLOWED_MYSQL_VERSION = null;//excluded
//List of allowed handlers
protected $expectedApi = array(
'cli',
'apache2handler'
);
//List of necessary Apache modules
protected $expectedApacheModules = array(
'mod_rewrite'
);
//List of allowed operating systems
protected $expectedOS = array(
'windows',
'linux'
);
//List of allowed architectures
protected $expectedArchitecture = array(
'amd64',
'x86_64'
);
//List of necessary PHP extensions
protected $expectedExtensions = array(//Extension name
'json',
'SPL',
'PDO',
'SimpleXML',
'curl',
'xsl'
);
//List of necessary PHP classes
protected $expectedClasses = array(//Class name
'Silex\Application',
'Monolog\Logger',
'Symfony\Component\Console\Application',
'Symfony\Component\Form\Form',
'Symfony\Component\Security\Core\SecurityContext',
'Symfony\Component\Translation\Translator',
'Symfony\Component\Validator\Validator',
'Swift_Mailer',
'Knp\Snappy\Pdf',
'Doctrine\ORM\EntityManager',
'Carbon\Carbon'
);
//List of necessary files with access rights
protected $expectedFileFolders = array(//Folder relative path form project root
'vendor/h4cc/wkhtmltopdf-amd64/bin/' => 'R',
'var/log' => 'RW',
'var' => 'RW'
);
/*
* DO NOT EDIT BELOW
*/
const METHOD_PREFIX = 'assert';
private $lineBreak;
private $apiSuffix;
public function __construct()
{
$this->lineBreak = ('cli' == php_sapi_name() ? "\n" : "<br/>");
$this->apiSuffix = ('cli' == php_sapi_name() ? "_CLI" : "_WEB");
}
public function execute()
{
//Loop through all check methods by introspection
$methods = get_class_methods(__CLASS__);
$finalReturn = true;
foreach ($methods as $method) {
if (self::METHOD_PREFIX == substr($method, 0, strlen(self::METHOD_PREFIX))) {
$return = $this->$method();
$finalReturn = $finalReturn && $return;
echo str_pad($method, 50, '.') . ($return ? 'OK' : 'KO <<<') . $this->lineBreak;
}
}
return $finalReturn;
}
protected function assertApi()
{
$api = php_sapi_name();
foreach ($this->expectedApi as $expectedApi) {
if (0 == strcasecmp($api, $expectedApi)) {
return true;
}
}
echo 'Current API : ' . $api . $this->lineBreak;
return false;
}
protected function assertOS()
{
$os = php_uname("s");
foreach ($this->expectedOS as $expectedOS) {
if ( false !== stripos($os, $expectedOS)) {
return true;
}
}
echo 'Current OS : ' . $os . $this->lineBreak;
return false;
}
protected function assertArchitecture()
{
$archi = php_uname("m");
foreach ($this->expectedArchitecture as $expectedArchitecture) {
if (0 == strcasecmp($archi, $expectedArchitecture)) {
return true;
}
}
echo 'Current Architecture : ' . $archi . $this->lineBreak;
return false;
}
protected function assertPhpVersion()
{
$return = true;
if (!is_null(self::MIN_ALLOWED_PHP_VERSION)) {
$return = version_compare(PHP_VERSION, self::MIN_ALLOWED_PHP_VERSION, '>=');
}
if (!is_null(self::MAX_ALLOWED_PHP_VERSION)) {
$return = $return && version_compare(PHP_VERSION, self::MAX_ALLOWED_PHP_VERSION, '<');
}
if(!$return) {
echo 'Current PHP version : ' . phpversion() . $this->lineBreak;
}
return $return;
}
protected function assertMemory()
{
$mem = intval(ini_get('memory_limit'));
$min = constant('self::MIN_ALLOWED_MEMORY' . $this->apiSuffix);
$max = constant('self::MAX_ALLOWED_MEMORY' . $this->apiSuffix);
$return = true;
if (!is_null($min)) {
$return = $mem >= $min;
}
if (!is_null($max)) {
$return = $return && ($mem <= $max);
}
if(!$return) {
echo 'Current memory : ' . $mem . $this->lineBreak;
}
return $return;
}
protected function assertExecutionTime()
{
$time = ini_get('max_execution_time');
$time = (0 != $time) ? $time : PHP_INT_MAX;
$min = constant('self::MIN_ALLOWED_EXECUTION_TIME' . $this->apiSuffix);
$max = constant('self::MAX_ALLOWED_EXECUTION_TIME' . $this->apiSuffix);
$return = true;
if (!is_null($min)) {
$return = $time >= $max;
}
if (!is_null($max)) {
$return = $time && ($mem <= $max);
}
if(!$return) {
echo 'Current execution time : ' . $time . $this->lineBreak;
}
return $return;
}
protected function assertApacheModules()
{
if (!function_exists('apache_get_modules')) {//By-pass
return true;
}
$modules = apache_get_modules();
foreach ($this->expectedApacheModules as $expectedApacheModule) {
if (!in_array($expectedApacheModule, $modules)) {
echo 'Missing module : ' . $expectedApacheModule . $this->lineBreak;
return false;
}
}
return true;
}
protected function assertExtensions()
{
$extensions = get_loaded_extensions();
foreach ($this->expectedExtensions as $expectedExtension) {
if (!in_array($expectedExtension, $extensions)) {
echo 'Missing extension : ' . $expectedExtension . $this->lineBreak;
return false;
}
}
return true;
}
}
//Launch check
$checker = new CheckPlateform();
return $checker->execute() ? 0 : -1;
preferences:
40.01 ms | 402 KiB | 5 Q