Top SEM and SEO Tips    

Archive for the ‘Web Design and Development’ Category

Unable to post message to http://googleads.g.doubleclick.net. Recipient has origin xxxx

Wednesday, December 28th, 2011

Had this issue on one site when running Chrome and after much hunting did not find a documented solution. However I did manage to find and correct the issue after a little playing with my code.

The issue ended up being a totally unrelated

tag with a float left (it was a div around the breadcrumbs). This tag was used on other pages with ads with no issues, just one page had this problem. Unfortunately it was the template for the main part of the site so the ‘unable to post message’ issue had to be fixed.

To track down if a ‘float left’ is the cause of your problem try removing all CSS style sheets and see if the ads now start working. If the Google ads do start working then you just need to add in parts of the CSS and retest until you narrow down the code that’s causing the issue.

In my code I was able to change the float left to a ‘text-align:left;’, the ads kept displaying and my look/feel was left intact.



WordPress How To Convert Tables to Innodb

Thursday, December 15th, 2011

Innodb tables are tables within MySQL that should be used instead of MyISAM for numerous reasons, the very least is that their transactional nature means they will not corrupt if you system has to reboot or lose power.

One of the problems is to change your tables from MyISAM to Innodb you need to run the following command:
ALTER TABLE YourDB.wp_posts ENGINE=InnoDB;
Once per table and that means lots of manual typing

I found a script that will create the list of tables for you:
SELECT CONCAT( 'ALTER TABLE `', table_schema, '`.`', table_name, '` ENGINE=InnoDB;' )
FROM information_schema.tables
WHERE ENGINE = 'MyISAM'
AND table_schema NOT
IN (
'information_schema', 'mysql'
)

Which outputs something like:
ALTER TABLE YourDB.wp_bad_behavior ENGINE=InnoDB;
ALTER TABLE YourDB.wp_commentmeta ENGINE=InnoDB;
ALTER TABLE YourDB.wp_comments ENGINE=InnoDB;
ALTER TABLE YourDB.wp_links ENGINE=InnoDB;
ALTER TABLE YourDB.wp_options ENGINE=InnoDB;

Which you can then cut and paste into any MySQL SQL window and run and all your tables are converted. The nice thing is if the script stops for some reason you can rerun the first script again without breaking anything.

Note – if you see ‘….’ at the end of the ‘ALTER TABLE’ lines this is phpMyAdmin truncating the output – turn on full text output and you’ll see the correct commans.



Reasons I did not renew with Inmotion Hosting

Friday, November 4th, 2011

Just received a invoice payment chaser from Inmotion Hosting. Thought I would share with you why I am not using their service anymore:

We moved off your servers months ago due to having the service turned off randomly, god awful support, and when we complained to your quality assurance department they said that your service was just fine. Well it wasn’t, we’re not on you anymore, and we’re not recommending you to anyone anymore.

While realizing we’re a small fish for you we were much bigger having multiple hosting accounts, a dedicated server and two VPS servers. We used your services for years. All our hosting needs are now off your servers. We moved the dedicated server to Amazon and now have 8 servers with them so you should consider your appalling service has cost you circa $3,000 per month plus any referrals we might have given you.

Turning off someone’s service is not acceptable, it costs money and hurts reputations. You might accuse people of abusing your service due to temporary load but turning off service makes me look bad in front of my bosses and I won’t stand for that.

Dylan



Convert WordPress Comments Form into a Table

Wednesday, November 2nd, 2011

If you’re fed up with your comment form fields not lining up properly here’s how to turn the form fields into a table which you can then use CSS to format.

In your theme’s functions.php file add the following code:

<php
add_action( 'comment_form_before_fields', 'uniquename_comment_form_before_fields' );
function uniquename_comment_form_before_fields() {
      echo '<table id="PostCommentTable">';
}
add_action( 'comment_form', 'uniquename_comment_form' );
function uniquename_comment_form() {
      echo '</td></tr></table>';
}
?>

Then in your comments.php file locate the line that reads ‘comment_form()’ and replace with the following:

<?php
$comment_args = array( 'fields' => apply_filters( 'comment_form_default_fields', array(
       'author' => '<tr><td>' .
       '<label for="author">' . __( 'Your Name' ) . '</label> ' .
       ( $req ? '<span>*</span>' : '' ) .
       '</td><td><input id="author" name="author" type="text" value="' .
       esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
       '</td></tr><!-- #form-section-author .form-section -->',
       'email'  => '<tr><td>' .
       '<label for="email">' . __( 'Your Email' ) . '</label> ' .
       ( $req ? '<span>*</span>' : '' ) .
       '</td><td><input id="email" name="email" type="text" value="' . esc_attr(         $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />' .
       '</td></tr><!-- #form-section-email .form-section -->',
       'url'    => '' ) ),
       'comment_field' => '<tr><td>' .
       '<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label></td>' .
       '<td><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
       '</td></tr><!-- #form-section-comment .form-section -->',
       'comment_notes_after' => '<tr><td>&nbsp;</td><td>',
);
comment_form($comment_args);
?>

This will then turn your comment form into a table with the id of PostCommentTable. Then simply add some CSS into your styles.css file (also in your theme directory):

#PostCommentTable td {
vertical-align:top;
padding:2px;
}
#PostCommentTable tr td:first-child {
text-align:right;
padding-top:8px;
}

And you end up with a really nice looking comment table



PHP and Memcached Returning Random Data

Thursday, September 15th, 2011

This took a long time to track down and only applies in specific circumstances:

  • Your process is forking
  • You are using persistent memcache connections
  • The data you request does not match what you receive, for instance you expect an array and an integer is returned.

The problem is caused by the persistent connection being shared after the process has forked. This is a known issue on database connections which is why you should always stop and restart your database connections after a process forks however this is not a documented ‘feature’ of the memcache connections. Trying to close and reopen the memcache connections doesn’t help either. What is happening is two processes are using the same pipe to talk to memcache, they both request data at roughly the same time however the responses go back to the wrong processes, so process A gets the data meant for B, and process B gets process A’s data.

The best approach I’ve found to this issue so far is:

  • Mark the data stored with the key it was stored under.
  • When the data is returned check the key returned to ensure its the same as the key requested.
  • If there is a mismatch treat it as a cache miss – return false.

This increases your cache misses however it ensures your application works as you coded. Its a simple change, instead of storing the just the data, you add an additional parameter to indicate the key the data was stored under:

Instead of:

function CacheAdd( $Key, $Data , $TTL ){
    // add code to create your memcache connection
    $memcache->add( $Key, $Data , false, $TTL );
}

You use:

function CacheAdd( $Key, $Data , $TTL ){
    // add code to create your memcache connection
    $DataToStore = array( 'Key'=>$Key, 'Data'=>$Data ) ;
    $memcache->add( $Key, $DataToStore , false, $TTL );
}

and then when you retrieve:

function CacheGet($Key){
    // add code to create your memcache connection
    $DataFromStore = $memcahe->get( $Key );
    if ( !isset($DataFromStore['Key']) || $DataFromStore['Key'] != $Key ) {
        return false;
    }
    return $DataFromStore['Data'];
}


PHP Processes Getting Killed

Monday, September 12th, 2011

This one took a while to suss out.

Symptoms are:

  • Database connections idle for long periods of time.
  • Processes start and then stop intermittently.
  • Processes report ‘Killed’ when you run them.
  • Running ‘dmesg’ from the command line shows the OMM process was called.

If this is happening to you you need to check your logs to see if the OMM (out of memory manager) is getting called. To check this run ‘dmesg’ from a Unix command line and look for the term ‘OMM’. The OM process kicks in when there is not enough memory to satisfy memory requests (malloc) that the system has already OKed. his is a particular problem on Linux as it will optimistically over allocate memory without regard to whether there is any actually available. The OMM process has this horrible habit of killing random processes until there is enough memory available. The processes killed are always user processes but are totally unrelated to whatever caused the memory issue in the first place.

There is a solution though. The solution is embedded in later versions of Linux and its a method to control the overallocation of memory allowed so that the OMM process is not called, instead the process that requested the memory is killed with a segmentation fault instead. It still means some process dies however its better than a random act of killing.

The solution was in the post killing the OOM killer – setting the two vm. variables in sysctl.conf stopped the OMM process kicking in and killing random processes. Looking at the ‘dmseg’ instead of OMM calls I now see seg faults. There is still a problem with overallocation of memory but now the process that requested the memory is killed rather than a random process.

My setting for the sysctl.conf file

vm.overcommit_ratio = 80

vm.overcommit_memory = 2

Which is working fine on an Amazon EC2 instance.



IE9 Beta First Impressions

Thursday, September 16th, 2010

After following the IE Blog for months about how great their new browser is they finally announced an open Beta. As I develop for the Internet I can’t install on my work machine as it might interfere with my testing of code on IE8 so last night I installed on two machines at home.

My main problem currently is the lack of speed in IE8. I run IE8 on a 2 year old laptop with 2GB RAM and it can take 30 seconds to start. The Javascript performance is appalling. The built in debugger is confusing. I generally work in Firefox 3 with Firebug which in comparison starts in less than 5 seconds, Firebug is really intuitive too and with the Web Developer plugin I get control of CSS on the fly – and ideal development environment.

First impression of the install – why do I need to reboot windows to install this? I don’t need to reboot for Firefox updates, nor most other software. Then on the reboot its obviously reconfiguring and installing something at the system level. Thought this tight integration wasn’t allowed any more? http://en.wikipedia.org/wiki/European_Union_Microsoft_competition_case Guess that doesn’t apply in the US.

So now we’re running IE9 Beta and gave it a test spin with Zillow.com. Initial reactions were that most sites just worked. The property details page failed to show the property map but otherwise worked fine.

My wife tried it going to Gmail but had issues with the application crashing and got a little fed up, but being Beta software some issues are to be expected.

I ran some of the browser benchmarks such as the IE Fish Tank and they run really smooth, much better than my Firefox installation at the office http://ie.microsoft.com/testdrive/performance/fishIE%20tank/default.html

The Speed Reading test is impossible to read on either IE9 or Firefox 3 – on IE9 its too quick, and on Firefox 3 its too slow to bother waiting for.

Overall the browser seems really nice, I’m really looking forward to the speed improvements in rich content, the other new features I didn’t see a point to yet. Some work on the remaining bugs and it should be a good upgrade.



Save HTML Table to Excel using jQuery

Friday, November 7th, 2008

After a few hours work looking into this, this turned out really easy to implement using jQuery and server side PHP programming as follows:

On the client side the following HTML code needs adding to the page (note this is older code – for newer code follow link at bottom):

<form action="/SaveToExcel.php" method="post" target="_blank"
onsubmit='$("#datatodisplay").val( $("&lt;div&gt;").append( $("#ReportTable").eq(0).clone() ).html() )'>
<input  type="image" src="/images/icons/Floppy-48x48.png" width="12" height="12" >
<input type="hidden" id="datatodisplay" name="datatodisplay" />
</form>

Note – variables used above – ReportTable is the id of the table you want to save and datatodisplay is a hidden variable used to post the table to the server.

The jQuery commands were added to the form’s onsubmit event but could easily be in your $(function(){}); fuction

The hard part here was getting all of the <table> HTML code. The standard jQuery .html() command gets the innerHTML and was cutting off the <table> HTML code. Getting all the HTML code was accomplished using the code $(“#datatodisplay”).val( $(“<div>”).append( $(“#ReportTable”).eq(0).clone() ).html() ) which effectively gets the outerHTML of the named HTML object (in this case the table we want to save to excel).

On the server side create a file called’SaveToExcel.php’ and add the following code:

<?php
header("Content-type: application/vnd.ms-excel; name='excel'");

header("Content-Disposition: filename=export.xls");
// Fix for crappy IE bug in download.
header("Pragma: ");
header("Cache-Control: ");
?>
<html>
<head></head>
<body><?=$_REQUEST['datatodisplay']?>
</body>
</html>

Updated: April 8, 2010 – modified to add fix for crappy IE download bug.
Update: September 11, 2011 – new version of jquery save to excel javascript code at http://www.topsemtips.com/2011/09/jquery-save-to-excel-ii/



More on PHP Error Handling

Wednesday, September 24th, 2008

OK so I’ve been talking about PHP errors for a while now but one more post. I found some code for customizing error handing in PHP , I installed it and got overwhelmed with emails reporting errors on my sites. I had to spend most of yesterday fixing issues on my sites. Most were minor issues of course – the worse is using uninitialized variables such as $ret = $Data['notset']; where the value in $Data hasn’t been set. In reality the code works and its being pedantic but it still needs fixing with:

$ret = isset( $Data['notset'] ) ? $Data['notset'] : “” ;

But some reports were real errors, such as unitialised variables that needed a value, referencing arrays using -> instead of [], and other nasties. Some I can do nothing about – WordPress plugins seem to be especially bad for using uninitialised variables. For now I’m using the code on custom applications and avoiding WordPress.



Typical Lazy PHP Programmer

Wednesday, August 27th, 2008

That’s me, write a program and it works, don’t bother initializing variables, etc. That was until I moved to a new host that had display errors turned off. It is pretty much impossible to debug without errors being displayed so I went rummaging around for ways around this and found the following code:

error_reporting(E_ALL);
ini_set(“display_errors”,1);

I turned this on and suddenly the code was spitting out warnings and messages all over the place. Some trivial but some really fixed issues that I didn’t know. Now I’ve got it turned on all the time in development and on internal systems.

As the ‘Practical PHP Programming’ manual says:
Always set your PHP error level to the most verbose level, E_ALL. All too often people don’t realise that PHP is outputting various complaints about variables not being set, etc, which you can just do away with entirely by cleaning up your code.