PHP代碼性能的分析方法
來源:易賢網(wǎng) 閱讀:839 次 日期:2014-08-21 16:55:09
溫馨提示:易賢網(wǎng)小編為您整理了“PHP代碼性能的分析方法”,方便廣大網(wǎng)友查閱!

php代碼的性能分析。

你可以用xdbug去分析。

但是更好的選擇是facebook的性能分析工具xhprof。

它可以圖形化。前提是你安裝了gd庫,你也可能遇到一些小問題。我記得要更新linux的圖像庫。

安裝xhprof擴展:pecl install xhprof .

<?php

/**

*

*

* Beck Confidential

* Copyright (c) 2013, Beck Corp. <Beck.Bi>.

* All rights reserved.

*

* PHP version 5

*

* @category Aug

* @package package_name

* @author beck

* @date 2013-8-13

* @license

* @link

*

*/

class Xhprof

{

protected $flags = 0;

protected $options = array();

protected $xhprofData = array();

/**

* 配置你的xhprof 你可以在php的官網(wǎng)看著個應用的說明

* @param unknown $config

* @throws ExtensionNotFoundException

*/

public function __construct($config = array())

{

if (!extension_loaded('xhprof')) {

throw new ExtensionNotFoundException(

'Configuration error! Make sure you have xhprof installed correctly.

please refer http://www.php.net/manual/en/xhprof.examples.php for detail.'

);

}

if (!empty($config['flags'])) {

$this->flags = (int)$config['flags'];

}

if (!empty($config['options'])) {

$this->options = $config['options'];

}

}

/**

* 開啟調(diào)試

*/

public function enable()

{

xhprof_enable($this->flags, $this->options);

}

public function disable()

{

$this->xhprofData = xhprof_disable();

}

/**

*顯示調(diào)試結(jié)果

* 你可能需要配置一個apache/nginx虛擬主機

*/

public function show()

{

$this->disable();

include_once "xhprof_lib/utils/xhprof_lib.php";

include_once "xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new XHProfRuns_Default();

$run_id = $xhprof_runs->save_run($this->xhprofData, "xhprof_testing");

echo "<a target='_blank'>see xhprof result</a>";

}

}

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:PHP代碼性能的分析方法

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)