Monday, May 20, 2013

Cache



Cache:

1. APC
2. Varnish
3. memcache

combination of all 3 is useful but use them for different things: Varnish: can cache static content and deliver it extremely fast (reducing load on apache)

APC: stores php opcode so that calls which are processed by php are faster

Memcache: use as a temporary data store for your application to reduce calls to your db (db is typically a bottleneck)
if you have time on your hands, go for it with all 3 in the following order:

APC (fast to get up and running)

Varnish (needs a bit of configuration but is well worth it for static pages)

Memcache (code changes to make use of it, so obviously needs more thought and time)

Saturday, January 26, 2013

MVC - SIMPLE EXAMPLE

MVC:
The MVC pattern separates an application in 3 modules: Model, View and Controller:

MODEL:

  • The model is responsible to manage the data; it stores and retrieves entities used by an application, usually from a database, and contains the logic implemented by the application.
VIEW:
  • The view (presentation) is responsible to display the data provided by the model in a specific format. It has a similar usage with the template modules.
CONTROLLER:
  • The controller handles the model and view layers to work together. The controller receives a request from the client, invoke the model to perform the requested operations and send the data to the View. The view format the data to be presented to the user, in a web application as an html output
MVC Diagram:


MVC Structure:

Controller

The controller is the first thing which takes a request, parse it, initialize and invoke the model and takes the model response and send it to the presentation layer. It’s practically the liant between the Model and the View, a small framework where Model and View are plugged in. In our naive php implementation the controller is implemented by only one class, named unexpectedly controller. The application entry point will be index.php. The index php file will delegate all the requests to the controller:
<?php

include_once ("controller/controller.php");

$controller = new Controller();
$controller->invoke();

?>

Our Controller class has only one function and the constructor. The constructor instantiate a model class and when a request is done, the controller decide which data is required from the model. Then it calls the model class to retrieve the data. After that it calls the corresponding passing the data coming from the model. The code is extremely simple. Note that the controller does not know anything about the database or about how the page is generated.

<?php

include_once("model/model.php");

class controller
{
public $model;


public function __constructor
{
$this -> model = new model();
}
public function invoke() {

if(isset(!$_GET['book']))
{

}
else {
}
}

}


?>