How to find out which part of PHP code loads CPU on the server?

0 like 0 dislike
42 views
A VDS with centos 7
want to optimize a php script with a large number of applications it strongly loads the CPU
how can I find the lines of code that affect it?
by | 42 views

5 Answers

0 like 0 dislike
Google "PHP profiling"
XDebug, XHprof, Blackfire ...

As well as "load testing"
jmeter ...

For a quick test short scripts: take measurements, cut out a piece of repeated measurements.
by
0 like 0 dislike
Typical places with problems:
session based access to the file system (default);
- sub-optimal calls to the database;
- long cycles (often with calls to the database).

Look for such places in your script, and then as advised Yan-s : take measurements, cut out a piece of repeated measurements.
by
0 like 0 dislike
1) Install the php extension xdebug
Enable this extension and profiling in xdebug settings
xdebug.profiler_enable = 1
Please note these 2 options (where to put profile files):
xdebug.profiler_output_dir
xdebug.profiler_output_name
2) Deflate the profiling I've found myself on a development machine, then feed it to this utility as QCacheGrind. It will quickly analyze them and give you what methods, how many times have you volunteered, and how much CPU time left for processing. You can sort the results.
3) xdebug In production better off.
by
0 like 0 dislike
by
0 like 0 dislike
offer supersymetry option.
in the beginning of the script place $start = microtime(true);
and code scattering printf(microtime(true) - $start);
by

Related questions

110,608 questions
257,186 answers
0 comments
33,729 users