Open SourceImplement the Singleton Pattern in PHP Without Taking a Performance Hit

Implement the Singleton Pattern in PHP Without Taking a Performance Hit

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories