PHP Performance Tuning Introduction - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Performance Tuning Introduction - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Saturday, July 6, 2019

PHP Performance Tuning Introduction

PHP Performance Tuning



Introduction


PHP is pretty speedy. Usually, the slow parts of your PHP programs have to do with external resources—waiting for a database query to finish or for the contents of a remote URL to be retrieved. That said, your PHP code itself may not be as efficient as it could be. This chapter is about techniques for finding and fixing performance problems in your code.

There’s plenty of debate in the world of software engineering about the best time in the development process to start optimizing. Optimize too early and you’ll spend too much time nitpicking over details that may not be important in the big picture; optimize too late and you may find that you have to rewrite large chunks of your application.

Optimization doesn’t happen in a vacuum. As you tweak your code, you’re not just adjusting raw execution time—you’re also affecting code size, readability, and maintainability. There are always circumstances that demand screamingly fast execution time. More frequently, however, programmer time or ease of debugging is a more valuable commodity. Try to balance these concerns as you tackle optimization hurdles in your code.

Installing a code accelerator is the best thing you can do to improve performance of PHP. As of PHP 5.5, PHP bundles and builds the Zend OPcache PHP accelerator, but OPcache works for PHP 5.2 and above.

If your application is still too slow, get started with integrating some easy analysis methods into your development routine. You want to identify which sections of your application are taking up the largest block of time. It’s hard to know in advance what those will be. It can be a section called once that’s very slow, or maybe a small function that’s quite fast, but is called frequently. The trick is quickly identifying the troublesome area in the code, which can be difficult as your application becomes larger and larger.

Here are five different ways to break apart your application at various levels: Shows you how to time the execution of a function, and expands on that to illustrate how to easily time all the function calls in a block of code. See how to profile code by statement and by self-defined sections. Finally, take these approaches even farther, which covers the use of a debugger extension for application profiling.

An overview of how to stress test your website reminds you that there’s more to performance tuning than the code itself—network latency and hardware also play a big role.

One of the most common bottlenecks in many PHP scripts is misuse of regular expressions; explains a few approaches to solving text-matching problems without incurring the overhead of regular expressions.

No comments:

Post a Comment

Post Top Ad