PHP ?? ??? ??? ???? ??
Jun 03, 2024 am 10:56 AMPHP ?? ??? ???? ???? ???? ???? Xdebug? ???? ?? ???? ?? ?? Cachegrind ??? ???? ?? ?????. Blackfire? ???? ?? ??? ?? ?? ???? ?????. ?????? ??? ???? ????? ??? ?????. ??? ???? ????, ??? ?? ? ?? ???? ?????.
PHP ?? ??? ??? ???? ??
PHP? ???? ?? ???? ???? ????? ?? ??? ????? ?? ??? ??? ?? ????. ??? ??? ???? ???? ??? ???? ???? ?? ?????. ? ????? PHP ?? ??? ???? ???? ???? ?? ??? ?????.
1. Xdebug? ???? ?? ??? ??
Xdebug? ???? ??? ?? ??? ?? ???? ??? ? ?? ??? PHP ?????. Xdebug? ????? ?? ??? ????.
pecl install xdebug
?? ? php.ini
??? ??? ?????. php.ini
文件中:
zend_extension=xdebug.so xdebug.profiler_enable=On xdebug.profiler_output_dir="/tmp" xdebug.profiler_output_name=cachegrind.out.%t.%s
2. 分析 Cachegrind 輸出
運行腳本后,Xdebug 將在 /tmp
目錄中生成一個 Cachegrind 輸出文件(cachegrind.out.<pid>.<script-name>
)。您可以使用 KCacheGrind(一個免費的 GUI 工具)或 pprof --callgrind
命令來分析此輸出文件。
3. 使用 Blackfire 查看請求跟蹤
Blackfire 是一個商業(yè)的 PHP 性能分析工具,提供了對請求執(zhí)行的深入見解。要使用 Blackfire,請安裝其 PHP 擴展并在您的腳本中添加以下代碼:
use Blackfire\Client; $client = new Client(); $client->startProfile();
在腳本完成后,使用以下命令生成性能報告:
blackfire report -profile=/tmp/blackfire/<profile-id>
4. 檢查數(shù)據(jù)庫查詢
數(shù)據(jù)庫查詢可能是 PHP 性能問題的常見源泉。要檢查查詢,請使用 Xdebug 或 Blackfire 來查看執(zhí)行的時間和數(shù)量。您還可以使用 MySQL 查詢分析工具(如 pt-query-digest
)來識別低效查詢。
5. 分析內(nèi)存使用情況
內(nèi)存使用過高會減慢腳本的執(zhí)行速度。要分析內(nèi)存使用情況,請使用 Xdebug 或 Blackfire 查看內(nèi)存分配和峰值使用情況。您還可以使用 memory_get_peak_usage()
PHP 函數(shù)來檢查腳本的最大內(nèi)存使用量。
實戰(zhàn)案例:診斷緩慢的 WordPress 網(wǎng)站
假設(shè)您有一個運行緩慢的 WordPress 網(wǎng)站。通過使用 Xdebug 分析 Cachegrind 輸出,您發(fā)現(xiàn)一個加載了大量帖子的頁面特別慢。進一步調(diào)查顯示,.
符號之前的數(shù)據(jù)庫表鏈接符(.
rrreee
/tmp
????? ?? Cachegrind ?? ??(cachegrind.out.<pid>.<script-name>
) KCacheGrind(?? GUI ??) ?? pprof --callgrind
??? ???? ? ?? ??? ??? ? ????. ????3. Blackfire? ???? ?? ?? ??????Blackfire? ?? ??? ?? ?? ???? ???? ?? PHP ?? ?? ?????. Blackfire? ????? PHP ??? ???? ????? ?? ??? ?????. ??rrreee??????? ??? ? ?? ??? ???? ?? ???? ?????. ??rrreee??4 ?????? ??? ?????. ?????????? ??? ??? ? ????. PHP ?? ??? ???? ?????. ??? ????? Xdebug ?? Blackfire? ???? ??? ??? ??? ??? ?????. pt-query-digest
? ?? MySQL ?? ?? ??? ???? ????? ??? ??? ?? ????. ????5. ??? ??? ????????? ??? ???? ???? ?? ??? ??????. ??? ???? ????? Xdebug ?? Blackfire? ???? ??? ?? ? ?? ???? ?????. memory_get_peak_usage()
PHP ??? ???? ????? ?? ??? ???? ??? ?? ????. ?????? ?: ?? WordPress ???? ???????? WordPress ????? ??? ??? ?????. Xdebug? ???? Cachegrind ??? ???? ?? ?? ???? ???? ???? ?? ?? ?? ??? ? ????. ?? ??? ?? .
?? ?? ?????? ??? ?? ??(.
)? ???? MySQL? ?? ?? ??? ???? ??? ??????. ? ??? ??? ? ??? ?? ??? ?? ???????. ??? ??? PHP ?? ??? ??? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

AI? ??? ??? ?? ?? ? ?? ???? ????? ?? ??? ??????. 1. Baidu, Tencent API ?? ?? ?? NLP ?????? ?? ??? AI ?? ?? API? ??????. 2. PHP? ? ?? guzzle? ?? API? ???? ?? ??? ??????. 3. ?? ????? ?? ?? ??? ???? ???? ???? ??? ??? ? ????. 4. ?? ?? ? ?? ???? ?? PHP-L ? PHP_CODESNIFFER? ??????. 5. ???? ????? ???? ?? ?? ??? ?????? ??? ??????. AIAPI? ??? ? ???, ?? ??, ?? ? PHP ?? ??? ??? ???. ?? ???? PSR ??? ???, ??? ????? ????, ?? ??? ???, ????? ??? ????, X? ???????.

PhpisstillRelevantinmodernenterpriseenvironments.1. Modernphp (7.xand8.x)? ??? ??, ??? ??, jitcompilation ? modernsyntax, mateitsuilableforlarge-scalepplications

N 1 ?? ??? ??? ?? ???? ?????? ?????? ?? ?? ????. 2. ???? ???? ???? ?? ??? ???????? ??? ??? ?? ? ??????. 3. ??? 2 ? ?? ?? Redis ?? ??? ?? ??? ?? ?? ??? ????? ??????. 4. ??? ????? ????? ????? Clear ()? ???? ???? ?????? ??? ????? ?????. 5. ?????? ??? ????? ???? ???? ? ??? ??? ?? ?? ? SQL ?? ??????. 6. ?? ??? ???? ?? ?????? ?? ?? ??? ?????? ?? ?? ?? ??? ???? ??? ??????. ORM? ???? ????? ?? ??? ????? ?? ???? ??? ???? ?? SQL ????, ??, ?? ?? ? ??? ???? ???????.

??? PHP ???? ???? ????? RabbitMQ? ???? ??? ??? ???? 1. ????? ??? ??? ?? ??? ???? ?? ???? ???????. 2. ???? ???? ?? ???? ???, ???? ???, ?? ? ?? ACK? ?????. 3. ?? ? ?? ? ??, TTL ? ?? ?? ? ?? ?? ??? ??????. 4. Supervisord? ?? ??? ???? ??? ????? ???? ??? ??? ???? ?? ?? ?? ????? ???????. ??? ????? ???? ??? ????? ???? ??? ?????.

Subprocess.run ()? ???? ? ??? ???? ???? ??? ??????. ?? ??? ??? ?? ??? ?? ??? ???? ?? ????. 2. ? ??? ??? ??, shell = true? ??? ? ??? ?? ??? ??????. 3. ?? ????? ???? ??? ?? ??? ??????. 4. SET Check = ??? ?? ? ? ??? ??? ?? true; 5. ??? ?????? ??? ?? ???? ??? ?? ? ????. OS.System () ?? ? ?? ???? ?? ??? ???? ???? ?? ???? Subprocess.run ()? ?? ??? ???????. ?? ??? ????? ? ??? ???? ?? ??? ?????.

??? PHP ?? ???? ???? ???? ?? ??? ? Docker ??? ???? ?? ?? ????? ?????. 1. PHP : 8.3-fpm-alpine? ?? ???? ???? ?? ??? ??? ??? ??????. 2. ??? ?? php.ini? ?? ??? ??? ??????, ?? ??? ??, Opcache ? JIT? ????? ?? ? ??? ??????. 3. Nginx? ??? ???? ???? ??? ??? ?? ???? ???? PHP ??? PHP-FPM?? ???? ?????. 4. ??? ??? ???? ???? ?? ???? ???? ????? ????? ??? ?? ???? ??????. 5. CRON? ?? ?? ????? ?????? ??? ?? ??; 6. ?? ?? ??? ?? ??? ??? ??????

settings.json ??? ??? ?? ?? ?? ?? ?? ??? ??? VSCODE ??? ??? ???? ? ?????. 1. ??? ?? ?? : Windows? C : \ Users \\ AppData \ Roaming \ Code \ User \ Settings.json, MacOS IS /users//library/applicationsupport/code/user/settings.json, linux? /home//.config/code/user/settings.json; 2. Workspace ?? ?? : .vscode/settings project root ????

PHP? ??? ?? ????? ?? ??? ??????????? ?? ??? ???? ?? ?? ??? ????????. 1. ?? ??? ??? ?? ??? ?? ? ?? ???? ?????. 2. ?? ???? ???? ???? ?? ? ? ???? GC? ?? ????? ???? ?????. 3. "??? ??"zval? ?? ?? ????? ???? GC_COLLECT_CYCLES ()? ?? ? ? GC? ??????. 4. ?? ?? PHP ?? ????? ??? ??? ??? ?? GC_STATUS ()? ?????? GC_COLLECT_CYCLES ()? ? ??? ???????. 5. ?? ???? ?? ??? ??? GC_DISABLE ()? ???? ?? ? ??? ????? ORM? CLER () ???? ?? DeReeference ??? ?????.
