dongpian4954 2012-03-09 17:43
浏览 103
已采纳

服务器基准测试PHP性能

I have several hosting accounts with different companies, and I'm trying to evaluate which one will run a stock Wordpress installation the fastest (without having to install wordpress on each of them first).

I found a php benchmarking script to try and determine which one would work best and I'm having strange results.

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

?>

Now on one server I'm getting an average of about 10, and on another 15 (so far so good), but on a third, the average is like 45 seconds. It's strange because that server has a working Wordpress install that runs pretty quickly (about 1.5 second page load times).

My question is, why might this server be showing me such high results, but seems to be working fine? And second, does this mean that this isn't a good method to determine which host would ultimately run Wordpress the fastest (all other things being equal)? And if this isn't a good method, do you have any suggestions?

  • 写回答

2条回答 默认 最新

  • douzha8489 2012-03-09 17:45
    关注

    You need to actually install wordpress to know for sure.

    I would just edit the index.php file of each and require this file.

    <?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');
    

    I've done benchmarking for a while and this will give you good information about the current memory usage and processing speed of the server. You could even hit the server with httperf a few hundred times to get TRUE server ability.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取