Tag Archives: PHP

Access Specifiers

It specify the level of access to the the data member or function in a class

Please note that all data members and member functions are public by default.

Private

A private access specifier is used to hide data and member functions. A method or data member declared as private can only be accessed by the class itself and neither the outside program nor the derived class can have access to it.

Public

A public access specifier allows the data members and methods to be access from anywhere in the script. Lets look at an example below:

protected

A protected access specifier allows the derived class to access the data member or member functions of the base class, whereas disallows global access to other objects and functions.
Example

<?php
class PHPCode{
private $a;
public $b;
public function __construct($a, $b) {
$this->b = $a;
$this->b = $b;
}
}

$obj = new PHPCode(7,17);
echo $obj->b;
?>
Here we can not access the variable a but b

The reason why data members are declared private is to avoid the outside programs to either accidentally modify the values without necessary validation.

When you define a method as private that method can only be called from within that class and not from outside that is the global level script.

Private data member or functions can not be accessed by the child class objects

Speed up magento

1) Install Fooman Speedste

http://www.magentocommerce.com/extension/457/fooman-speedster

2) Enable Gzip Compression in .htaccess

Add “php_flag zlib.output_compression on” in .htaccess file

3) Install APC or Xcache or memcached

4) Make sure your Apache configuration has KeepAlives enabled

5) Modify the configuration for your MySQL server to take better advantage of your server’s RAM.

6) Use a memory-based filesystem for Magento’s var directory

7) Clustering

8 ) Optimizing MySQL Database

9) Magento Caching.

10) Remove Home Page Elements

11) Compressing CSS Files

12) Changes to MySQL Configuration

13) Change from Apache to Litespeed Web Servers

KeepAlives

KeepAlives are a trick where multiple HTTP requests can be funneled through a single TCP connection. Since the setup of each TCP connection incurs additional time, this can significantly reduce the time it takes to download all the files (HTML, JavaScript, images) for a website.”

Alternative PHP Cache

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code. Besides a opcode cache it provides a user cache for storing application data. This module uses the APC user cache as a cache backend for Drupal.

Memcached

Memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load

In computing, memcached is a general-purpose distributed memory caching system that was originally developed by Danga Interactive for LiveJournal, but is now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Memcached runs on Unix, Linux, Windows and MacOSX and is distributed under a permissive free software license.

Memcached’s APIs provide a giant hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order. Applications using Memcached typically layer requests and additions into RAM before falling back on a slower backing store, such as a database.

Prototype Pattern

The prototype class lets you use many instances of a specific class, without copying objects to different variables.

The most customizable option for programmatic creation is the Prototype pattern. This pattern consists in choosing an already existent object, with a clone() operation available, as the base for creating new objects of the same kind.

In the Prototype Pattern we create one standard object for each class, and clone that object to create new instances.

Service Locator Pattern

The service locator pattern is a design pattern used in software development to encapsulate the processes involved in obtaining a service with a strong abstraction layer. This pattern uses a central registry known as the “service locator” which on request returns the information necessary to perform a certain task.

It allows overrides or renamed physical resources .

The “service locator” can act as a simple run-time linker. This allows code to be added at run-time without re-compiling the application, and in some cases without having to even restart it.

Applications can optimize themselves at run-time by selectively adding and removing items from the service locator. For example, an application can detect that it has a better library for reading JPG images available than the default one, and alter the registry accordingly.

Large sections of a library or application can be completely separated. The only link between them becomes the registry.

 

Registry Pattern

The Registry pattern provides a mechanism for storing data globally in a well managed fashion, helping to prevent global meltdown.

The goal of the registry pattern is simply to provide client code with a mechanism which allows you to save and retrieve resources across different points of an application. In general creating a basic registry using an object-oriented approach demands that you build a class containing the methods required to perform the saving/retrieval tasks.

A registry is a container for shared objects. In the really basic version, you could use an array. As such, the variable $GLOBALS could be called a registry.