Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created May 21, 2014 19:14
Show Gist options
  • Save Sigmus/ff591944a55ca2c11c1c to your computer and use it in GitHub Desktop.
Save Sigmus/ff591944a55ca2c11c1c to your computer and use it in GitHub Desktop.
Diagnósticos do projeto em PHP
<?php
// Altere as configurações
$config = array(
'version' => '5.3.7',
'max_size' => '10M',
'dir' => 'exemplo_escrita',
'database' => array(
'host' => 'localhost',
'database' => 'copa',
'username' => 'root',
'password' => 'root'
),
'tabela' => 'exemplo_tabela'
);
$configVersion = explodeVersion($config['version']);
$currentVersion = explodeVersion(phpversion());
if ($currentVersion[0] < $configVersion[0] or $currentVersion[1] < $configVersion[1] or (($currentVersion[1] < $configVersion[1]) and ($currentVersion[2] < $configVersion[2]))) {
print "<strong>Versao " . phpversion() . " nao eh suficiente </strong>. Minima exigida " . $config['version'] . '<br>';
}
else {
print "Versaoo " . phpversion() . " eh suficiente (minima exigida " . $config['version'] . ") <br>";
}
function explodeVersion($version) {
$aux = explode('.', $version);
$first = (int) $aux[0];
$second = (int) $aux[1];
$third = (int) $aux[2];
return array($first, $second, $third);
}
print "<code>";
if ( function_exists('mcrypt_cbc')) {
print "mcrypt ........................ instalado <br>";
}
else {
print "mcrypt ........................ não instalado <br>";
}
$postMaxSize = ini_get('post_max_size');
$uploadMaxSize = ini_get('upload_max_filesize');
$configMaxSize = $config['max_size'];
print "post_max_size ................. $postMaxSize <br>";
print "upload_max_filesize ........... $uploadMaxSize <br>";
print "configurado.................... $configMaxSize <br>";
if ((int) $uploadMaxSize > (int) $postMaxSize) {
print "erro *** <strong>post_max_size</strong> deve ser maior ou igual a <strong>upload_max_filesize</strong> ***<br>";
}
if ((int) $postMaxSize < (int) $configMaxSize) {
print "erro *** <strong>post_max_size</strong> deve ser maior ou igual a <strong>$configMaxSize</strong><br>";
}
if ((int) $uploadMaxSize < (int) $configMaxSize) {
print "erro *** <strong>upload_max_filesize</strong> deve ser maior ou igual a <strong>$configMaxSize</strong><br>";
}
$dir = $config['dir'];
if (is_writable($dir)) {
print "permissao escrita $dir videos... ok<br>";
}
else {
print "erro *** dir <strong>$dir</strong> precisa ter permissao de escrita<br>";
}
try {
$host = $config['database']['host'];
$database = $config['database']['database'];
$username = $config['database']['username'];
$password = $config['database']['password'];
$conn = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
print "conexao mysql.................. ok<br>";
$tabela = $config['tabela'];
$data = $conn->query("SELECT * FROM `$tabela` LIMIT 1");
print "tabela $tabela. existe<br>";
} catch(PDOException $e)
{
print "erro *** <strong>banco de dados com probema:</strong> ". $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment