15 Dec

WordPress How To Convert Tables to Innodb

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_behaviorRead the rest

04 Nov

Reasons I did not renew with Inmotion Hosting

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.… Read the rest

02 Nov

Convert WordPress Comments Form into a Table

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' ) .
Read the rest
15 Sep

PHP and Memcached Returning Random Data

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.… Read the rest

12 Sep

PHP Processes Getting Killed

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.… Read the rest

16 Sep

IE9 Beta First Impressions

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.… Read the rest

07 Nov

Save HTML Table to Excel using jQuery

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.… Read the rest

24 Sep

More on PHP Error Handling

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.… Read the rest

27 Aug

Typical Lazy PHP Programmer

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.… Read the rest

15 Jul

Make WordPress Mobile Friendly

Following on my theme for this week, here are the steps to make WordPress mobile friendly. This assumes you are using a separate URL for your mobile friendly wordpress (such as sitename.mobi):

1 – Buy your domain and park it on your current WordPress site, so sitename.com and sitename.mobi are generating the same content

2 – Add (or modify) the file /wp-content/themes/yourtheme/functions.php and add the following lines:

<?php
remove_action(‘template_redirect’, ‘redirect_canonical’);

function elixir_urlrewrite( $url ) {… Read the rest