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

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
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 | 62 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.
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.
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):
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.
0 like 0 dislike
0 like 0 dislike
offer supersymetry option.
in the beginning of the script place $start = microtime(true);
and code scattering printf(microtime(true) - $start);

Related questions

110,608 questions
257,187 answers
40,796 users