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 29, 2010 11:55 am

-

All developers have to transfer sites at some point, if you don’t I envy you. It seems that site transfers always have teething issues with the difference in server builds, operating systems having different compilations of PHP and the rest.

And worst of all, different hosts limitations…

But to transfer a site you need to make a simple list of things that need to be done in order for it to work.

  • Get all files, including hidden files (many a time I’ve been caught up on the .htaccess on a mac being hidden and a site riddled with 404 errors…)
  • Get all database details of the new server
  • Update all calls to databases
  • Use Dream Weaver (for the only things its any good for) to search and replace across the site for the old URL and change it to the new one, and the same with database details)
  • Make sure image, stylesheet, javascript and any other call is base root not an absolute URL (unless externally hosted)
  • Upload everything, including creating the new databases
  • Test everything, fix bugs and teething issues

If you can do all of the above your site will transfer easy peasy.

Posted by: SEO Positive

Posted on: November 22, 2010 9:18 am

-

Anyone asking for the ability to pull data off another website or to globalise a collection of links or anything you want will come across the file_get_contents function. This function is very useful for data scraping or for generalising a collection of links or general content.

The function itself does nothing but puts the source of the web page you supply it into a string available for use throughout your script.

It does have sister functions such as file() which puts the source code into an indexed array (a new array element for every line of code) and CURL.

While there are a huge number of solutions to doing this, file_get_contents is for me the easiest as with regular expressions its unstoppable.

To use file_get_contents():

$data = @file_get_contents( "http://www.bbc.co.uk/" );
if( $data ) echo htmlentities( $data );

The above will output the source code of the very latest BBC home page (with html entities so you get the source not just a reconstructed bbc home page)

Using regular expressions you can pull any piece of data throughout the source code.

Posted by: SEO Positive

Posted on: November 17, 2010 9:23 am

-

We’re big fans of WordPress at SEO Positive, purely for its ease and speed of development as well as the sheer number of awesome plugins.

But WordPress also has a habit of being “too good” and puts quite a substantial amount of junk code in your websites/blogs, this tutorial will show you how to remove this code.

WordPress Header Stripping

WordPress has a habit of putting a lot of tags in your header that generally aren’t needed such as the “index”, “EditURL”, “next” and “generator” meta and link tags. These are surprisingly easy to strip out because WordPress has a great function to do just that.

remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_generator' );

The above will remove pretty much all of the junk out of your WordPress headers leaving them squeeky clean. For an example of what this strips out visit SEO Positive and view the source.

To use the above code, simply paste this into your themes functions.php and save/refresh your page to see the difference.

WordPress “role” attributes

WordPress is a very semantically conscious CMS and blogging system and this is proven by viewing your template source and noticing the “role” attribute on most of the containers throughout the code.

The role attribute is NOT just a WordPress piece of code and you CAN delete these but these are fairly clever pieces of code aimed for search engines. Its kind of (simply put) the closest thing to the semantic-ness of HTML 5 or XHTML 2. The role attribute is to distinguish what each container is used for, see here for the documentation on this attribute.

I will briefly explain the most important and used “role” attributes below:

  • role=”banner”
    • This is to tell engines and screen readers that this is the primary area for images, big text and advertisements.
  • role=”navigation”
    • This is to distinguish navigational buttons for the website, its only recommended to have the one of these any sub menus (seperate columns etc) just leave as they are not primary navigational areas.
  • role=”main”
    • This is the most important of the roles as this tells everything that this is the main content area of the website

WordPress is filled with all kinds of clever bits and bobs to help you develop your sites/blogs and with a range of plugins to help you achieve your perfect site. We use SEO Ultimate to help us diagnose our websites and better achieve SEO domination which contains fantastic tools for inserting code into your headers and footers for analytics and validation tags etc.

Posted by: SEO Positive

Posted on: November 15, 2010 9:17 am

-

Sometimes we all wonder if changing our domains URL will benefit our SEO campaigns? recently SEO Positive have changed from our 3 year .com domain to a more UK specific .co.uk and successfully implemented a way of doing so seamlessly.

When changing a URL it really comes down to the direction of your old visitors to your new url and we decided the best solution as the site was not changing physically was to 301 each and every page, but with any ReWriteRule you can’t just write 900 separate rules to achieve this so I cam up with a clever little rewrite rule of my own to automatically redirect with the page name attached so all pages are technically the same.

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.seo-positive.co.uk/$1 [R=301,L]

The above code is very simple and for any regular expression new comer the explanation of each line is below

Options +FollowSymLinks

All this does is tell the Apache to follow symbolic links (links that don’t hold any physical value, as in the file is missing)

RewriteEngine on

This tells Apache that it should initialise the mod_rewrite module ready for usage, and the final piece to the puzzle is the below code.

RewriteRule (.*) http://www.seo-positive.co.uk/$1 [R=301,L]

The first part “(.*)” tells Apache that the file we want to redirect is a simple wildcard for everything, the second part is the url we want to redirect to appended with $1, this is the internal ID set by Apache to the wildcard search. The third and final part is the method in which to redirect R=301 means to redirect the file with a 301 header meaning “Moved Permanently” and the “L” at the end means this is the LAST redirect rule allowed to initiate.

Happy transferring!

Posted by: SEO Positive

Posted on: November 5, 2010 8:51 am

-

The world of the internet is edging toward the search engines, there is nothing more important than the search engines available to the world wide web and with the web turning ever more dynamic its also becoming harder to build a search engine friendly website.

But the clever guys at apache managed to create a solution for us called mod_rewrite

What is mod_rewrite?

mod_rewrite is a technology used to mask “ugly URL’s” into search engine friendly alternatives using the clever regular expressions engine.

Whats an ugly url?

An ugly URL would be:

www.seopositive.com/?page=10

If there are ugly url’s there are pretty urls?

yes, there are pretty urls these are what mod_rewrite achieve.

So how do I do this?

Well there are literally hundreds of mod_rewrite rule generators out there to help you turn your site into an search engine monster and for content management systems such as wordpress you can generalise your rules.

But the first step is to create a file called .htaccess in the root of your website, for a CMS such as wordpress the rules are

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

The above doesn’t look like much but it makes the difference between an ugly url, non search engine friendly and generally SEO fail website into what could be an SEO monster.

Once you have put all the necessary rules into your .htaccess file. Save it, close it, upload it and test your websites pretty urls.

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: October 6, 2010 8:16 am

-

Continuing on from a previous post about page speed, anything built in PHP beyond something simple should be class based to prevent duplication of code and keep your web pages  as small as possible.

But what are PHP Classes?

Well PHP Classes ventures into the OOP area (That’s Object Orientated Programming) and a class is a collection of functions, variables and general behavior depending on your class structure.

This is an example of a PHP class.

//mordor.php
class my_precious
{
         public static function mordor($ring = null)
         {
                   if($ring !== 'ring') return "Well... Where's the ring? I don't want your {$ring}";
                   else return 'Well... That\'s all evil taken care of... Gratz';
         }
}

So as you can see, its fairly simple to do. Really its just keeping your code in one collated name space, without the above code being in a class the most efficient way to deal with that would be to build a whole line of if and else statements to capture any data on any page you wanted to display your Mordor paddy.

Of course when you’re building massive projects classes may seem a lot more efficient but the above code was a syntax example. To use the above code, all you need on any page is the below code.

require 'mordor.php';
echo my_precious::mordor('Cheese and ham Toastie');

Which we’ll all agree is a lot less hassle than writing a script and copy and pasting it all over every page you want the validation/script to run on. Having to only put 2 lines of code into a page will keep your page sizes down and involves a lot less on page server action with if and else statements littered everywhere to catch and modify data in and out of the page.

While procedural code may have some advantages for building a website with PHP, unless its a single query and including an entire class and its children is entirely arbitrary PHP Classes are the way to go forwards.

Happy coding!

Posted by: SEO Positive

Posted on: September 28, 2010 8:28 am

-

So many PHP developers, in no limited skill set generally lack the knowledge of the APC which is an acronym for Alternate PHP Cache. And cutting a long story short the APC is a virtual memory storage to keep your variables in while retaining them across multiple web pages, and throughout your code.

It is a great way of speeding up, and minimizing your code, if used correctly. When I first began using it, I was almost scared of its technicality but I was reassured after a quick read on php.net (your best friend, as a PHP developer.)

The PHP is, largely, not installed as a default module on every server and the module will be need to be installed if you want take advantage of it.

The functions you’re more than likely to use are:

  • apc_store($name, $value, $time=null);
  • apc_fetch($name);
  • apc_delete($name);
  • apc_exists($key);

apc_store($name, $value);

This function, as you might imagine, Does nothing more than store a variable into the APC for arrays of objects you do need to alter the way that you instantiate your array object. See below for an example:

$myArray[] = new foo();//assuming these classes do nothing but echo their namespaces and PHP_EOL
$myArray[] = new bar();// " "
//now lets store it.
apc_store('arrayObject', new ArrayObject($myArray));
//and fetch it.
$apcElement = apc_fetch('arrayObject');
//and output it all.
var_dump($apcElement);

The output will be along the lines of

foo
bar

but in essence, the storing of objects isn’t recommended as you will not store the information, simply the properties of that object.

apc_fetch($name);

So assuming we have used apc_store(‘foo’, ‘bar’); we can now use apc_fetch(‘foo’); see the example below

//set
apc_store('foo', 'bar');
//get
apc_fetch('foo');
//will output "bar"

Which as you can see, is incredibly easy to use. Overall, the usability of the APC is almost perfect.

apc_delete($delete);

This is, again, very simple to use and self explanatory.

//set
apc_store('foo', 'bar');
//get
var_dump(apc_fetch('foo'));
//delete
apc_delete('foo');
//get, to test
var_dump(apc_fetch('foo'));

again, very simple, precise and to the point.

And lastly, of the functions you’re most likely to use. The validation of a properties existence within the APC.

apc_exists($key);

This simple validation checks whether or not the key you have supplied exists within the stored apc array. See below for usage instructions.

if(apc_exists('foo')) echo 'the property exists within the APC ' . PHP_EOL;
else echo 'The property does not exist, try setting it?' . PHP_EOL;

This is a very simple validation example, and I can’t stress enough that these examples shouldn’t be used in a live environment, simply learn from them and if you get stuck, remember, php.net is your best friend.

Posted by: SEO Positive

Posted on: July 2, 2010 8:07 am

-

Well PHP 6 has been announced for a while now, and nothings been heard in a long time about it so just to enlighten some PHP devs I will do my best to update you all as to the plans of possibly the best thing since Firefox came out.

And firstly quite possibly one of the best things they’ve done is removed, safe_mode, magic_quotes and register_globals. Phew! Thank god for that, PHP developers will find these raise E_CORE_ERROR now and will have to build ‘good code’ and perhaps even integrate software architecture to build their applications in PHP.

Bold move by the PHP team, but a good one at least…

And another purely genius amendment is the inclusion of E_STRICT into E_ALL forcing developers to build at least half decent applications (sorry guys, if you’re old school this is bad news) this is GREAT news, here at SEO Positive we get a lot of half baked car crash websites with code that is barely readable and needs rebuilding to include new additions.

A few other changes to appear in PHP 6 (if PHP 6 is what they plan on calling it, sources say that its now just a branch oh PHP rather than a re-release or upgrade but we’ll see.)

Var – normally used in classes is now just an alias for public. Great move of the PHP team

returning anything by reference $foo =& new StdClass – this will give you an E_STRICT error (Watch out Joomla!!!)

Register long arrays is going now, for good. Thank god! I see these in code all the time, and just wonder how old the programmer must be.. (Stone age?)

Freetype and GD1 are going now for good as well, this doesn’t really matter because no one uses these incredibly old libs anymore.

Support for the ASP style opening and closing tags is to go now as well. Thank the lord… ASP? really? *sigh*

Static and dynamic functions being called statically. Not possible anymore, this will cause an E_FATAL from now onwards. (learn your classes people)

These are just a few of the changes that PHP 6 will entail, there are many many more in fact. Too many to list in a simple blog post but I was simply letting all you devs know that PHP 6 (Or any other imminent rebuild/upgrade to PHP) is still an action in the background happening.

I can’t wait for this to hit the mainstream, development will change (and the internet will possibly crash and burn with the number of scripts that are going to die with the upgrade)

Authors
Categories
Archives
Blogroll