Posted by: Shofiur Rahman

Posted on: August 15, 2012 4:03 pm

-

Zen optimizer acts in a similar way to APC and eAccelerator. It caches the compiled state of PHP scripts, enabling faster execution on consequent requests. To accelerate the performance of PHP scripts, Zen Optimizer also allows us to run scripts encoded by Zend Encoder on the server.

Installing Zend Optimizer

Installing the Zend Optimizer is easier than the other caching solutions, as it comes with a setup wizard.

To install Zend Optimizer follows the steps below:

  1. Download the appropriate package from http://zend.com/store/products/zend-optimizer.php.
  2. Decompress the archive, and go into the newly created directory:

    tar -xvzf ZendOptimizer-2.5.10a-linux-glibc21-i386.tar.gz

    cd ZendOptimizer-2.5.10a-linux-glibc21-i386

  3. Run the install wizard as root:

    ./install.sh

    Run through the wizard, specifying the necessary paths when prompted.

  4. At the end, restart Apache.

Removing Zend Optimizer

To remove Zend Optimizer follows the steps below:

  1. Delete the symbolic link it created for php.ini.
  2. Restore the backed-up original php.ini file to its former location.
  3. Restart Apache

The Zend Optimizer will no longer be active. Now we can delete the Zend Optimizer files—the default location is /usr/local/Zend.

Posted by: SEO Positive

Posted on: November 3, 2010 9:12 am

-

Method chaining is becoming an increasingly popular technique in the programmers world, but not a lot of people understand it.

This short tutorial will hopefully shed light on:

  1. what it is
  2. what it does

So what is method chaining?

To answer this question I have to show you some basic classes, see below for a standard class and method set.

class random_functions{
     function format($string, $f = 'uppercase'){
            switch($f){
                 case 'uppercase':
                       $string = strtoupper($string);
                 break;
                 case 'lowercase':
                       $string = strtolower($string);
                 break;
             }
             return $string;
     }
     function strings($string, $filter = 'trim'){
            switch($filter){
                  case 'trim':
                         $string = trim($string);
                  break;
                  case 'mres':
                         $string = mysql_real_escape_string($string);
                  break;
             }
             return $string;
      }
}

To use the above class, instantiation is the usual

$functions = new random_functions();
echo $functions->strings($functions->format($string, 'lowercase'), 'mres');

Which, to me at least, looks awful, its hard to read and just generally not very easy to work with.
What method chaining allows us to do is keep our functions separate and make our re-usable code a lot easier to read and understand as this requires a lot of logical thought in to how you want it to work and even makes planning easier due to having to put your functions in the correct order to achieve what you want.

See below for the same class that allows method chaining.

class random_functions{

     static $output = '';

     function format($string, $f = 'uppercase'){
            switch($f){
                 case 'uppercase':
                       self::$output = strtoupper($string);
                 break;
                 case 'lowercase':
                       self::$output = strtolower($string);
                 break;
             }
             return $this;
     }
     function strings($string = '', $filter = 'trim'){
            switch($filter){
                  case 'trim':
                         self::$output = $string ? trim($string) : trim(self::$output);
                  break;
                  case 'mres':
                         self::$output = $string ? mysql_real_escape_string($string) : mysql_real_escape_string(self::$output);
                  break;
             }
             return $this;
      }
      function output($in = ''){
             echo $in ? $in : self::$output;
             return $this;
      }
}

And the use of this is much clearer and much easier, see below for the use and an explanation of the code.

$functions = new random_functions();
$functions->format('Foo Bar', 'lowercase')->strings()->output();

As you can see, there are arrows between each function call, this is called method chaining. This helps us keep our code clean, semantic and easy to read and understand.

Lets analyze the code

In order to make things easier I added a class variable to work from, this variable is available to every function within the class and I use it to validate input to functions and give us something to work from and around if needed. I also changed each return.

Instead of returning our formatted string, I’ve changed each return to $this what $this means is “the current object” which in a class means the class object.

The class object?

Classes are objects, with children (the methods/functions within the class) and to make any function chainable within a class all you have to do is return an object. You cannot make static methods chainable i.e

class random_functions{

     static $output = '';

     static function format($string, $f = 'uppercase'){
            switch($f){
                 case 'uppercase':
                       self::$output = strtoupper($string);
                 break;
                 case 'lowercase':
                       self::$output = strtolower($string);
                 break;
             }
             return $this;
     }
    static function strings($string = '', $filter = 'trim'){
            switch($filter){
                  case 'trim':
                         self::$output = $string ? trim($string) : trim(self::$output);
                  break;
                  case 'mres':
                         self::$output = $string ? mysql_real_escape_string($string) : mysql_real_escape_string(self::$output);
                  break;
             }
             return $this;
      }
     static function output($in = ''){
             echo $in ? $in : self::$output;
             return $this;
      }
}

random_functions::format('Foo Bar', 'lowercase')::strings()::output();

Will not work, this will return a fatal error.

But to make a static method chainable you must return a new object as $this is undefined in a static method as the parent becomes self

We hope that you enjoyed this tutorial and its helped you understand the ideology of method chaining and how it is useful.

Posted by: SEO Positive

Posted on: June 29, 2010 8:11 am

-

So there are a number of PHP frameworks out there, hundreds in fact but how do you know which one is best?

Well it depends on who you are and what you do, then it depends on your project, and a third argument to this is how long do you have to finish your project?

All things to consider whenever you’re thinking of changing your working pattern/s

If you’re a beginner to PHP and don’t understand what a framework is I’ll explain as best and as simply as I can below.

A framework, in this case for PHP, is a collection of scripts and or extensions to make and utilize PHP’s native functionality faster, more coherent and safer.

So whats an MVC?

If the said framework boasts about being an MVC framework, MVC is Model View Controller. This simply means its built with classes, objects and namespaces meaning its easy to extend, make chain-able etc (There generally just better, its not worth arguing)

So what are the top frameworks?

A quick Google search suggests that the top frameworks are (in no particular order)

  • Zend Framework
  • CakePHP
  • dFramewerk
  • CodeIgniter
  • Yii

And personal experience with each one is good, so I’ll tell you my tales first hand. Zend Framework is a massively complicated framework, but it is equally massive-ly helpful and technical great for large scale future proof sites.

CakePHP is a PHP framework for Ruby lovers, the framework was modeled on Ruby’s structure and is therefor great for creating Ruby styled applications

dFramewerk is a very simple framework aimed for beginners, extend-able and incredibly easy to learn (easiest out of the above in my personal opinion) and powerful, Built with jQuery’s famous ‘Do more, Write less’ motto in mind.

codeIgniter is a fantastic framework for building medium to large websites and applications with a very light footprint on your code and a non-restrictive style of coding.

Yii is a performance based PHP framework (and probably my least favorite from all of the above) it is a very raw framework and I sometimes wonder about its purpose and if it should be classed as a framework. But hey ho I shan’t spit stones at it. Its very raw and very extendable and as close as you can get to coding PHP, not recommended for beginners.

So to gauge what framework for what project, you should think how big is the site going to start off as and how big, how quickly, do you think it will get because you don’t want to be redeveloping your website now do you?

At SEO Positive we use a mixture of the dFramewerk and a customised codeIgniter set up so to offer my recommendations would be biased, but these are my personal favorites and they’re both great for beginners to learn and long term, great performers.

Authors
Categories
Archives
Blogroll