コード例 #1
0
ファイル: DB.php プロジェクト: dmamontov/benchmark-tools
 /**
  * Speed test select 1000 records.
  * @return array|boolean
  * @final
  */
 public final function SpeedSelect()
 {
     if ($this->MyIsam()) {
         $type = 'MYISAM';
     } elseif ($this->Innodb()) {
         $type = 'InnoDB';
     } else {
         return false;
     }
     $result = false;
     $table = $this->db->prepare("CREATE TABLE test_table (test varchar(100), test2 varchar(50), test3 varchar(30), test4 text) ENGINE={$type}");
     if ($table->execute()) {
         $time = Tools::getTime();
         for ($i = 0; $i < 1000; $i++) {
             $insert = $this->db->prepare("INSERT INTO test_table VALUES ('test1','test2','test3','test4')");
             if ($insert->execute() == false) {
                 return false;
             }
         }
         $time = Tools::getTime();
         $select = $this->db->prepare("SELECT * FROM test_table");
         if ($select->execute() == false) {
             return false;
         }
         $result = array('value' => round(1000 / (Tools::getTime() - $time)), 'postfix' => 'q/sec.');
         $table = $this->db->prepare('DROP TABLE IF EXISTS test_table;');
         $table->execute();
     }
     return $result;
 }
コード例 #2
0
ファイル: Http.php プロジェクト: dmamontov/benchmark-tools
 /**
  * Checks work sessions via http.
  * @return boolean
  * @static
  * @final
  */
 public static final function Sessions()
 {
     if (Server::PHPInterface() == 'cli' || Server::Sockets() === false || FileSystem::FileDeletion() === false) {
         return false;
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_session.php")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_session.php");
     }
     @session_start();
     $_SESSION['test_session'] = true;
     @session_write_close();
     $file = @fopen("{$_SERVER['DOCUMENT_ROOT']}/test_session.php", 'wb');
     @fputs($file, "<?php\n" . "@session_start();\n" . "if (\$_SESSION['test_session'] === true) {\n" . "    unset(\$_SESSION['test_session']);\n" . "    echo true;\n" . "} else {\n" . "    echo false;" . "}\n" . '?>');
     @fclose($file);
     $body = 'GET ' . dirname($_SERVER['PHP_SELF']) . "/test_session.php HTTP/1.1\r\n" . 'Host: ' . Tools::getHost() . "\r\n" . 'Cookie: ' . session_name() . '=' . session_id() . "\r\n\r\n";
     $result = file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_session.php") ? Tools::CreateRequest($body) : false;
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_session.php")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_session.php");
     }
     return $result;
 }
コード例 #3
0
 /**
  * Checking upload big files to the server.
  * @param integer $size
  * @return boolean
  * @static
  * @final
  */
 public static final function UploadsBigFile($size = 1024)
 {
     global $count, $js;
     if (Server::PHPInterface() == 'cli' || Server::PHPFileUploads() === false || FileSystem::FileDeletion() === false) {
         return false;
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_big.dat")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_big.dat");
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_big_upload.php")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_big_upload.php");
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_big_uploader.php")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_big_uploader.php");
     }
     $file = @fopen("{$_SERVER['DOCUMENT_ROOT']}/test_big_upload.php", 'wb');
     @fputs($file, "<?php\n" . "if (isset(\$_FILES['filename']) && is_uploaded_file(\$_FILES['filename']['tmp_name'])) {\n" . "    @move_uploaded_file(\$_FILES['filename']['tmp_name'], \$_REQUEST['root'] . '/test_big.dat');\n" . "    echo file_exists(\$_REQUEST['root'] . '/test_big.dat');\n" . "}\n" . "@unlink(__FILE__);\n" . '?>');
     @fclose($file);
     $file = @fopen("{$_SERVER['DOCUMENT_ROOT']}/test_big_uploader.php", 'wb');
     @fputs($file, "<?php\n" . "ini_set('display_errors', false);\n" . "@error_reporting(-1);\n\n" . "\$text = str_repeat(str_repeat('*', 1023) . \"\\n\", {$size});\n" . "\$boundary = sha1(1);\n" . "\$file = \"--\$boundary\\r\\n\" .\n" . "         \"Content-Disposition: form-data; name=\\\"filename\\\"; filename=\\\"test_big.dat\\\"\\r\\n\" .\n" . "         \"Content-Type: text/plain; charset=us-ascii\\r\\n\" .\n" . "         \"Content-Length: \" . (1024 * {$size}) . \"\\r\\n\" .\n" . "         \"Content-Type: application/octet-stream\\r\\n\\r\\n\" .\n" . "         \"\$text\\r\\n\" .\n" . "         \"--\$boundary--\";\n\n" . "\$body = \"POST " . dirname($_SERVER['PHP_SELF']) . "/test_big_upload.php?root={$_SERVER['DOCUMENT_ROOT']} HTTP/1.1\\r\\n\" .\n" . "         \"Host: " . Tools::getHost() . "\\r\\n\" .\n" . "         \"Content-Type: multipart/form-data; boundary=\$boundary\\r\\n\" .\n" . "         'Content-Length: ' . strlen(\$file) . \"\\r\\n\" .\n" . "         \"Connection: Close\\r\\n\\r\\n\" .\n" . "         \$file;\n\n" . "if (file_exists(\"{$_SERVER['DOCUMENT_ROOT']}/test_big_upload.php\")) { \n" . "    \$res = @fsockopen('" . Tools::getHost() . "', " . ($_SERVER['SERVER_PORT'] ? $_SERVER['SERVER_PORT'] : 80) . ", \$errno, \$errstr, 3);\n" . "     if (\$res) {\n" . "          \$time = explode(' ', microtime());\n" . "          \$time = (float) \$time[0] + (float) \$time[1];\n" . "          fputs(\$res, \$body);\n" . "          \$result = end(explode(\"\\n\", fread(\$res, 4096)));\n" . "          fclose(\$res);\n" . "          \$finishtime = explode(' ', microtime());\n" . "          \$finishtime = (float) \$finishtime[0] + (float) \$finishtime[1];\n" . "          \$time = round(\$finishtime - \$time, 2);\n" . "          echo \$result == '1' ? \"Yes \$time s\" : 'No';\n" . "     } else {\n" . "         echo 'No';\n" . "     }\n" . "} else {\n" . "    echo 'No';\n" . "}\n" . "@unlink('{$_SERVER['DOCUMENT_ROOT']}/test_big_upload.php');\n" . "@unlink('{$_SERVER['DOCUMENT_ROOT']}/test_big.dat');\n" . "@unlink(__FILE__);\n" . '?>');
     @fclose($file);
     $cnt = $count + 1;
     $js .= "\$('#value-{$cnt}').parent('tr').removeClass().addClass('active');\n" . "\$('#value-{$cnt}').siblings('.loader').html('<img src=\"https://www.crazydogtshirts.com/skin/frontend/mtcolias/default/images/loader.gif\"/>');\n" . "\$.get( \"" . dirname($_SERVER['PHP_SELF']) . "/test_big_uploader.php\", function(data) {\n" . "    \$('#value-{$cnt}').siblings('.loader').children().remove();\n" . "    \$('#value-{$cnt}').parent('tr').removeClass();\n" . "    if (data == 'No' || data == '') {\n" . "        \$('#value-{$cnt}').html(data);\n" . "        \$('#value-{$cnt}').parent('tr').addClass('danger');\n\n" . "    } else {\n" . "        \$('#value-{$cnt}').html(data);\n" . "        \$('#value-{$cnt}').parent('tr').addClass('success');\n\n" . "    }\n" . "})\n" . ".fail(function() {\n" . "    \$('#value-{$cnt}').siblings('.loader').children().remove();\n" . "    \$('#value-{$cnt}').html('No');\n" . "    \$('#value-{$cnt}').parent('tr').addClass('danger');\n" . "})\n";
     return 'Wait';
 }
コード例 #4
0
 /**
  * Checking upload files to the server.
  * @return boolean
  * @static
  * @final
  */
 public static final function FileUploads()
 {
     if (Server::PHPInterface() == 'cli' || Server::PHPFileUploads() === false || self::FileDeletion() === false) {
         return false;
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test.dat")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test.dat");
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_upload.php")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_upload.php");
     }
     $file = @fopen("{$_SERVER['DOCUMENT_ROOT']}/test_upload.php", 'wb');
     @fputs($file, "<?php\n" . "if (isset(\$_FILES['filename']) && is_uploaded_file(\$_FILES['filename']['tmp_name'])) {\n" . "    @move_uploaded_file(\$_FILES['filename']['tmp_name'], \$_REQUEST['root'] . '/test.dat');\n" . "    echo file_exists(\$_REQUEST['root'] . '/test.dat');\n" . "}\n" . '?>');
     @fclose($file);
     $text = 'Test upload';
     $boundary = sha1(1);
     $file = "--{$boundary}\r\n" . "Content-Disposition: form-data; name=\"filename\"; filename=\"test.dat\"\r\n" . "Content-Type: text/plain; charset=us-ascii\r\n" . "Content-Length: 11\r\n" . "Content-Type: application/octet-stream\r\n\r\n" . "{$text}\r\n" . "--{$boundary}--";
     $body = 'POST ' . dirname($_SERVER['PHP_SELF']) . "/test_upload.php?root={$_SERVER['DOCUMENT_ROOT']} HTTP/1.1\r\n" . 'Host: ' . Tools::getHost() . "\r\n" . "Content-Type: multipart/form-data; boundary={$boundary}\r\n" . 'Content-Length: ' . strlen($file) . "\r\n" . "Connection: Close\r\n\r\n" . $file;
     $result = file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_upload.php") ? Tools::CreateRequest($body) : false;
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test.dat")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test.dat");
     }
     if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_upload.php")) {
         @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_upload.php");
     }
     return $result;
 }
コード例 #5
0
 /**
  * Searches for java scripts on the site
  * @param string $regxHtml
  * @param string $regxFind
  * @param string $regxVersion
  * @return array|boolean
  * @final
  */
 private static final function search($regxHtml, $regxFind, $regxVersion = null)
 {
     global $docroot;
     if (Server::PHPInterface() == 'cli' || Server::PerlRegex() == false) {
         return false;
     }
     $root = $docroot && empty($docroot) === false ? $docroot : $_SERVER['DOCUMENT_ROOT'];
     $content = false;
     $port = $_SERVER['SERVER_PORT'] ? $_SERVER['SERVER_PORT'] : 80;
     $html = file_get_contents(($port == 443 ? 'https://' : 'http://') . Tools::getHost());
     if (preg_match($regxHtml, $html, $regx)) {
         if (stripos($regx[1], 'http') === false) {
             if (stripos($regx[1], '//') === false) {
                 $regx[1] = ($port == 443 ? 'https://' : 'http://') . Tools::getHost() . "/";
             } else {
                 $regx[1] = "http:{$regx[1]}";
             }
         }
         $content = file_get_contents($regx[1]);
     }
     if ($content == false && function_exists('exec')) {
         exec("find {$root} -name \"*.js\" -exec grep \"{$regxFind}\" {} \\; | head -n 1", $out);
         $content = reset($out);
     }
     if (is_null($regxVersion) == false && preg_match($regxVersion, substr($content, 0, 2000), $regx)) {
         return array('value' => true, 'version' => empty($regx[1]) == false ? reset(explode(' ', $regx[1])) : '');
     } elseif ($content !== false) {
         return true;
     }
     return false;
 }
コード例 #6
0
ファイル: OS.php プロジェクト: dmamontov/benchmark-tools
 /**
  * The amount of RAM.
  * @return array|boolean
  * @final
  */
 public static final function RAM()
 {
     if (function_exists('exec') == false) {
         return false;
     }
     exec('free -m | grep Mem | awk \'{ print $2 }\'', $memory);
     return Tools::FormatSize(reset($memory) * 1048576);
 }