July 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Implement the Singleton Pattern in PHP Without Taking a Performance Hit

  • November 26, 2010
  • 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


Tags: PHP 5, design patterns

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


Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel