January 25, 2021
Hot Topics:

Implement the Singleton Pattern in PHP Without Taking a Performance Hit

  • By Glen Kunene
  • Send Email »
  • More Articles »

Part of the well-known Gang of Four (GoF) design patterns, the Singleton pattern calls for restricting the instantiation of a class to one object. Implemented correctly in PHP, this pattern can facilitate powerful and robust applications.

In her PHPBuilder article, Implementing the Singleton Pattern in PHP 5, Octavia Anghel explains how to implement the Singleton pattern in different ways for different purposes in PHP 5. She writes:

The Singleton pattern fits well when you manage a shared resource -- a printer, a file manager, a database connection, loggers, and so on -- because your application should have only a single instance in order to avoid conflicting requests for the same resource and to minimize performance issues.

Integrating design patterns into your PHP applications can lead to performance issues if you don't do it right. Octavia demonstrates the proper way to implement the Singleton pattern in PHP.


Read the full story at PHPBuilder:
Implementing the Singleton Pattern in PHP 5

Originally published on https://www.developer.com.

This article was originally published on November 26, 2010

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date