Slow Function Execution

Description: When a specific function in your code runs slowly, Zend Monitor identifies it as an event worth reporting. The “Slow Function Execution” Rule contains the following monitoring definitions, runtime duration and a list of functions that should be monitored.

Information Collected:

The most important details are:

  • Function Name - As displayed in the Issue’s General Details
  • Function Arguments - The arguments of the function that triggered the event are listed in the Function Data tab.

In most cases, these details alone should be enough to indicate what happened to trigger an event.

Applicable Diagnostic Actions:

Click on a link to see how to perform each action tools are listed in order of relevance to helping solve the event:

  • Run the Profiler
  • Open code in editor
  • Run the Debugger
  • Use URL Tracing to collect further information about this function in action.

Possible Causes and Solutions:

Queries to a DB (database) - long, elaborate and complicated DB queries may take a long time and make the function appear to take a long time to execute.
There are many ways to speed up DB queries such as:

  • Revise the SQL query itself - make it simpler
  • Improve the structure of your DB tables
  • Use RDBMS features that can improve speed such as indexes, prepared statements, stored procedures etc…
    All these are only suggested possible causes and each event. Developers have to analyze each occurrence to understand the specific reasons behind the slow execution time.

Long running actions - Some actions triggered by a function can, by definition take a long time. Examples of long running actions can be using a function to run code from the command line or remote access queries with Web services or searching for files in a directory. In most cases, these uses of a function cannot be refined and the best action is to ignore these issues when they occur.

False Positives - Sometimes functions run slowly. Not all functions that run slowly are indicative of a problem in your code or environment and they may be no indication of unacceptable behavior. If this is the case, remove the function from the Rule’s “Watched Functions” list or set issues triggered by this function to ignored.