服务器基准测试php性能


Server benchmarking php performance

我在不同的公司有几个托管帐户,我正在努力评估哪一个会以最快的速度运行Wordpress股票安装(而不必首先在每个公司上安装Wordpress)。

我找到了一个php基准测试脚本,试图确定哪一个最有效,但我得到了奇怪的结果。

<?php
/*
##########################################################################
#                      PHP Benchmark Performance Script                  #
#                         © 2010 Code24 BV                               # 
#                                                                        #
#  Author      : Alessandro Torrisi                                      #
#  Company     : Code24 BV, The Netherlands                              #
#  Date        : July 31, 2010                                           #
#  version     : 1.0                                                     #
#  License     : Creative Commons CC-BY license                          #
#  Website     : http://www.php-benchmark-script.com                     #  
#                                                                        #
##########################################################################
*/
    function test_Math($count = 140000) {
        $time_start = microtime(true);
        $mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
        foreach ($mathFunctions as $key => $function) {
            if (!function_exists($function)) unset($mathFunctions[$key]);
        }
        for ($i=0; $i < $count; $i++) {
            foreach ($mathFunctions as $function) {
                $r = call_user_func_array($function, array($i));
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }

    function test_StringManipulation($count = 130000) {
        $time_start = microtime(true);
        $stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "soundex", "ord");
        foreach ($stringFunctions as $key => $function) {
            if (!function_exists($function)) unset($stringFunctions[$key]);
        }
        $string = "the quick brown fox jumps over the lazy dog";
        for ($i=0; $i < $count; $i++) {
            foreach ($stringFunctions as $function) {
                $r = call_user_func_array($function, array($string));
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }

    function test_Loops($count = 19000000) {
        $time_start = microtime(true);
        for($i = 0; $i < $count; ++$i);
        $i = 0; while($i < $count) ++$i;
        return number_format(microtime(true) - $time_start, 3);
    }

    function test_IfElse($count = 9000000) {
        $time_start = microtime(true);
        for ($i=0; $i < $count; $i++) {
            if ($i == -1) {
            } elseif ($i == -2) {
            } else if ($i == -3) {
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }   

    $total = 0;
    $functions = get_defined_functions();
    $line = str_pad("-",38,"-");
    echo "<pre>$line'n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|'n$line'nStart : ".date("Y-m-d H:i:s")."'nServer : {$_SERVER['SERVER_NAME']}@{$_SERVER['SERVER_ADDR']}'nPHP version : ".PHP_VERSION."'nPlatform : ".PHP_OS. "'n$line'n";
    foreach ($functions['user'] as $user) {
        if (preg_match('/^test_/', $user)) {
            $total += $result = $user();
            echo str_pad($user, 25) . " : " . $result ." sec.'n";
        }
    }
    echo str_pad("-", 38, "-") . "'n" . str_pad("Total time:", 25) . " : " . $total ." sec.</pre>";
?>

现在,在一台服务器上,我的平均时间约为10秒,在另一台上为15秒(到目前为止还不错),但在第三台服务器上的平均时间大约为45秒。这很奇怪,因为服务器有一个运行速度很快的Wordpress安装程序(大约1.5秒的页面加载时间)。

我的问题是,为什么这个服务器会向我显示如此高的结果,但似乎工作得很好?第二,这是否意味着这不是一个确定哪台主机最终运行Wordpress最快的好方法(所有其他条件都相同)?如果这不是一个好方法,你有什么建议吗?

您需要实际安装wordpress才能确定。

我只需要编辑每个的index.php文件,并需要这个文件。

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */
require('benchmark.php');
/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');

我已经做了一段时间的基准测试,这将为您提供有关服务器当前内存使用情况和处理速度的良好信息。你甚至可以用httperf攻击服务器几百次,以获得真正的服务器能力。

您必须安装wordpress才能分析每一个的性能。事实上,你应该在这三个插件中都安装完整的wordpress环境,我的意思是,所有wordpress插件都应该安装,因为它们可能会对性能产生很大影响。此外,apache、mysql和php应该在所有三个服务器中进行相同的调优。

一旦你做到了,你就可以使用jMeter(http://jmeter.apache.org/)以真正测试您的服务器,并查看您的服务器可以服务多少请求。