虚拟主机/云主机/VPS/云服务器 CPU 性能以及硬盘 I/O 如何,可以使用简单的一段 PHP 代码来测试,测试结果可以作为参考判断
PHP 代码如下
<?php echo 'PHP 版本:'.PHP_VERSION."<br>"; $mod = php_sapi_name(); echo 'PHP 运行模式:'.$mod."<br>"; //apache2handler //PHP 有多种运行模式,例如:apache、 apache2filter、apache2handler、 caudium、cgi //cgi-fcgi、cli、 cli-server、 continuity、embed、fpm-fcgi 等等。 #---------------------------------------------I/O 测试---------------------------------------------- // 记录开始时间 $starttime = getMicrotime(); // 读取 100000 次文件 for($i=0; $i<100000; $i++){ file_get_contents('test.txt');//在同目录下建立个 text.txt 文件,写入一些内容 } // 记录结束时间 $endtime = getMicrotime(); printf("I/O 时间:%f ms", ((float)($endtime)-(float)($starttime))*1000); echo '<br>'; function getMicrotime(){ list($usec, $sec) = explode(' ', microtime()); return (float)$usec + (float)$sec; } class PerformanceTest { private $time; private $memory; public function begin() { $this->time = $this->getTime(); $this->memory = $this->getMemory(); } public function end() { $this->time = $this->getTime() - $this->time; $this->time = round($this->time,7);//在这里才能格式化时间 $this->memory = $this->getMemory() - $this->memory; $this->memory = $this->convert($this->memory); echo "计算时间:{$this->time}秒<br />"; echo "内存使用:{$this->memory}<br />"; } public function getTime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } public function getMemory() { return memory_get_usage(); } public function convert($size) { $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } } $a = array(); $b = new PerformanceTest(); $b->begin(); for($i=0;$i<500000;$i++){ $a[$i] = $i; } foreach($a as $i) { array_key_exists($i, $a); } $b->end(); ?>
Vetrue.com 所用的云服务器 运行结果如下:
由于 Vetrue.com 所用服务器 开启了目录验证,
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
,所以硬盘 I/O 时间增加了大概三倍,不过为了安全考虑,建议开始开启目录验证,即便网站程序中了 PHPWebSHELL 等木马,以及网站权限未设置好,PHPWebSHELL 都无法跳出网站主目录读取和修改其他网站内容,比起性能,安全更重要