Archived video

This video is archived and won't be updated. We're keeping it online for now as a courtesy.

PHP Applications Profiling in PhpStorm

Video loading...

  • 0:04
    PhpStorm Video Tutorial PHP Applications Profiling in PhpStorm
  • 0:12
    Using PhpStorm, we can analyze performance of our PHP code
  • 0:17
    by profiling it.
  • 0:18
    Profiling allows us to get program execution statistics,
  • 0:22
    such as the names of functions executed, the number of times
  • 0:26
    a function has been called, how long a function took to execute,
  • 0:29
    and so on.
  • 0:30
    This information can give us a hint on where our code can be improved.
  • 0:36
    Profiling data is gathered by Xdebug or Zend debugger.
  • 0:40
    Instructions on how to enable any of these two
  • 0:42
    can be found in the web help, or in the debugging PHP topic.
  • 0:47
    In my case, I've configured the Xdebug profiler to output data
  • 0:51
    to the C:\Temp\Profiling folder on my system.
  • 0:55
    Note that in my php.ini, I have not
  • 0:58
    enabled profiling by default.
  • 1:00
    Profiling adds some overhead to program execution,
  • 1:03
    and it should only be enabled when needed.
  • 1:06
    We can do it is by specifying a php.ini option at run time,
  • 1:10
    like in the example shown on screen.
  • 1:14
    To start profiling, we can simply run our scripts.
  • 1:17
    The Xdebug or Zend debugger extension
  • 1:20
    will then gather all statistics related to the program execution.
  • 1:25
    Using the Tools, Analyze Xdebug Profiler Snapshot menu,
  • 1:30
    we can open a profile or snapshot and start analyzing it.
  • 1:35
    In the Execution Statistics view, we can examine the summary information
  • 1:39
    about execution metrics of every called function.
  • 1:43
    We can see all function calls, the number of calls,
  • 1:46
    and the time they took to execute.
  • 1:48
    We can also see the relative amount of time they took to execute,
  • 1:52
    so we can quickly see which files are taking the most time to run.
  • 1:57
    The Code Preview shows us the execution parts of our Code.
  • 2:01
    We can see more details about function execution times and so on.
  • 2:05
    As we can see here, the setActiveSheetIndex function
  • 2:08
    is called seven times, and consumes 8% of execution time.
  • 2:13
    Perhaps we can change our code to make less calls to this function.
  • 2:18
    At the bottom of this window, we can see function Callees and Callers.
  • 2:22
    These two tabs allow us to see all places in our code
  • 2:25
    where a call to a function is made.
  • 2:28
    If we select the setActiveSheetIndex function
  • 2:31
    and click the caller step, we see it's
  • 2:33
    being called in our index.php file.
  • 2:38
    We can also profile unit tests.
  • 2:40
    To do this, just make sure that the test
  • 2:42
    configuration enables profiling.
  • 2:45
    Once done, we can run all tests, and again use the Tools, Analyze Xdebug
  • 2:49
    Profiler Snapshot menu to open the profile snapshot
  • 2:53
    and start analyzing it.
Loading ...

PHP Applications Profiling in PhpStorm


Profiling allows you to gather program execution statistics, like the number of functions, or how long a function takes to run. In this tutorial we walk through profiling with XDebug in PhpStorm.

Additional resources: 

Please note that this series covers PhpStorm versions 6 and 7 only.

For the latest documentation (including up-to-date videos), see JetBrains documentation.