XHProf是一个分层PHP性能分析工具。它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况。现在我们来聊聊XHProf在开发环境中如何测试php性能。
以百分之一的概率产生测试数据,尽量不影响正式环境效率。
class XHProf { // private $XHProfPath = 'xhprof/'; private $XHProfPath = '/usr/local/apache/htdocs/xhprof/'; private $applicationName = 'sias_application'; private $sampleSize = 100; private static $enabled = false; public function XHProf_Start() { if (mt_rand(1, $this->sampleSize) == 1) { include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_lib.php'; include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(XHPROF_FLAGS_NO_BUILTINS + XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); self::$enabled = true; } } public function XHProf_End() { if (self::$enabled) { $XHProfData = xhprof_disable(); $XHProfRuns = new XHProfRuns_Default(); $XHProfRuns->save_run($XHProfData, $this->applicationName); } } }
测试效果:
Overall Summary Total Incl. Wall Time (microsec): 48,162 microsecs Total Incl. CPU (microsecs): 32,994 microsecs Total Incl. MemUse (bytes): 2,773,464 bytes Total Incl. PeakMemUse (bytes): 2,867,664 bytes Number of Function Calls: 749
从以下测试结果看出,耗时最多的居然是连接数据库,所以我们来尽量优化数据库。
本文地址:
转载随意,但请附上文章地址:-)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.