Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By : Sai S Sriparasa
Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By: Sai S Sriparasa

Overview of this book

Table of Contents (17 chapters)
Building a Web Application with PHP and MariaDB: A Reference Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Performance optimization for PHP


Now that we have discussed a good number of optimization techniques for our Apache web server and MariaDB, let us look at a few best practices that will help us optimize the performance of our PHP code. In this section, the best practices that we will go over are as follows:

  • Closing any open resource connections

  • Reducing the number of calls to the database

  • Encouraging the use of JSON data format for data exchange.

It is always recommended to close out any open resource connections such as database connections or file handles. The resources can get intensive on the machine as the number of the requests for database connections and file handles increase. Therefore, it is not a good idea to keep any of these connections open. The next technique to help us optimize performance would be to reduce the number of calls to the database, mainly if the database is not on the same machine as the web server. Network resources and bandwidth have to be factored into this decision...