Too many wordpress tags?

If you had a plugin a few years ago like SEO SearchTerms Tagging 2 or others that added tags to posts when people searched for those terms.
You might find now that your theme has hundreds of tags that are not used or barely used, cluttering up your site.

So here’s a little SQL you can use to clean up those tags.


DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );
DELETE FROM wp_term_taxonomy WHERE term_id not IN (SELECT term_id FROM wp_terms);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);

This removes all tags with 0 posts. Change the wp_term_taxonomy WHERE count = 0 to wp_term_taxonomy WHERE count = 1 and you’ll remove all the tags used only once. change the 1 to a 2 and you’ll remove all the tags only used twice etc etc..

Skype 6.22 is horrible!

if like me you got a skype update forced upon you (i’m sure i had told it not to update but anyway)

you ended up with something like this.

skype

My version was worse than that picture. It had an incredibly pale blue and even paler blue bubbles for the conversations.

That combined with all the white really put me off using it as it hurt my eyes.

Solutions!

http://download.skype.com/msi/SkypeSetup_6.21.0.104.msi Download the 6.21 skype client and hope they don’t force a new update on you or….

https://code.google.com/p/skype4pidgin/ along with https://www.pidgin.im/ uses the Skype api so you can use the messenger part without having to deal with their horrible ui!

php-fpm on Cpanel

After experimenting with mod_ruid2 and mod_fcgi in cpanel i found that the php speed just wasn’t as good as it should be.

I was really missing an opcode system. I prefer to use APC as it is actively developed by the php team themselves.

With mod_ruid2 APC works quite well but you are restricted to use apache prefork which uses lot of resources.

With mod_fcgi APC doesn’t work as well as it quickly eats up all your ram as the opcode isn’t shared. You can use mpm_worker though so this is an upside.

With php-fpm and mod_fastcgi being the ultimate solution but unfortunately cPanel still haven’t included php-fpm within their nice easyapache install system.

Someone on the cpanel forums has managed to get php-fpm up and running and you can find the instructions here.

http://forums.cpanel.net/f189/php-fpm-fastcgi-apc-293802.html

I have modified it so that it uses a socket and fixed the users for the current apache 2.2.24

I got it working.

Code:

/var/cpanel/easy/apache/rawopts/all_php5

contains
Code:

–enable-fastcgi
–enable-fpm

Then you recompile php and apache using easyapache with the mpm worker selected.

Then you have to set up your
Code:

/etc/init.d/php-fpm

script which you copy from
Code:

/home/cpeasyapache/src/php-5.3.16/sapi/fpm/init.d.php-fpm.in

Then you have to fill in your variables at the top of the file:
Code:

#! /bin/sh

### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=
exec_prefix=

php_fpm_BIN=/usr/local/sbin/php-fpm
php_fpm_CONF=/usr/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid

php_fpm_BIN
you might have to locate or create each of these files. php-fpm was in the path for me.
Code:

type php-fpm

gave me that.

php_fpm_CONF
i copied
Code:

/home/cpeasyapache/src/php-5.3.16/sapi/fpm/php-fpm.conf.in

to
Code:

/usr/etc/php-fpm.conf

I had to edit it too for my user and group that apache runs under, this will vary server to server so you’ll have to see what permissions your apache server needs
Code:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user’s group
; will be used.
user = nobody
group = nobody

and comment out the ip and change it to a socket.

;listen = 127.0.0.1:9000
listen = /tmp/php-fpm.sock

php_fpm_PID=/var/run/php-fpm.pid

You will have to create this file it won’t have permissions to create it itself even ran as root for some reason:
Code:

touch /var/run/php-fpm.pid

Having fun yet? K now you need to make apache use it for php.
Code:

vim /usr/local/apache/conf/includes/post_virtualhost_global.conf

you’re going to need to add this to the end of the file:

Code:

LoadModule fastcgi_module modules/mod_fastcgi.so


FastCGIExternalServer /usr/sbin/php-fpm -socket /tmp/php-fpm.sock
AddHandler php-fastcgi .php

#
# SetHandler php-fastcgi-virt
# Action php-fastcgi-virt /usr/sbin/php-fpm.fcgi virtual
#

Action php-fastcgi /usr/sbin/php-fpm.fcgi
ScriptAlias /usr/sbin/php-fpm.fcgi /usr/sbin/php-fpm


Options ExecCGI FollowSymLinks
SetHandler fastcgi-script
Order allow,deny
Allow from all

Don’t get ahead of yourself yet, we still haven’t compiled mod_fastcgi from source:
For which I followed this guide:
FastCGI for Apache2

Obviously ignore the bit about installing apache, as we already did that start with the part you download fastcgi.

You’ll have to change the source a bit differently than he lists tho here was my makefile:
Code:

#
# Makefile for Apache2
#

builddir = .

top_dir = /home/cpeasyapache/src/httpd-2.2.24

top_srcdir = ${top_dir}
top_builddir = ${top_dir}

include ${top_builddir}/build/special.mk

APXS = /usr/local/apache/bin/apxs
APACHECTL = /usr/local/apache/bin/apachectl

#DEFS=-Dmy_define=my_value
#INCLUDES=-Imy/include/dir
#LIBS=-Lmy/lib/dir -lmylib
INCLUDES=-I /home/cpeasyapache/src/httpd-2.2.24

all: local-shared-build

clean:
-rm -f *.o *.lo *.slo *.la

Then I ran into a problem with it not being able to create/read the log which would make nothing work:

Code:

touch /usr/var/log/php-fpm.log
chmod 777 /usr/var/log/php-fpm.log

chmod 777 is taboo and I’ll fix it soon but it got it able to read it when nothing else seemed to.

Lastly restart/start both of them:
Code:

/etc/init.d/php-fpm restart
/etc/init.d/httpd restart

Result: Well I’ve been optimizing our server for 2 weeks and this was the last thing. I’d already gotten the server response/page load time for our ecommerce php store to 500 to 600ms per product detail page according to firebug from times over 1.5 seconds. Now it’s down to no larger than 437ms. You can blink and miss it seriously. It’s well worth the effort I’ve never seen an ecommerce site this fast that runs off a php cart. It took me about 6 or 7 hours of researching around looking up info. Hopefully this will let someone else do it in far less time (my prior post was made a while after I’d started).

Inode problems

So i discovered my server had ran out of inodes yet had lots of space left.

This caused quite a few problems for me!

After a quick search i found

find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n

at root showed me where the inodes were being used.

A little deeper investigation i discovered this post on cpanel’s forums

http://forums.cpanel.net/f5/strange-directory-inside-root-270191.html

so with the cpanel script

/usr/local/cpanel/bin/purge_dead_comet_files

I could purge the old comet files and release all those inodes again!

I had previously been under attack from spam email.

Server load problems. Varnish vs Nginx vs Apache vs PHP DSO vs FCGI vs suPHP vs APC vs eAccelerator vs memcached

After noticing one of my servers was down i needed a solution to the server load problems i was having.

My sites on the server usually handle the loads that are on them but i was getting a huge spike in traffic that was causing the server to start swapping in and out of the swap….. which snowballed and caused the server to go from a load average of about 1 to well over 100!!!

What was to be done?

I already use supercache on all my sites along with widget cache.  This helps greatly but the problem is i am running multiple sites on these servers and i really need to prevent the servers from becoming overloaded.

 

I was using Apache + mod_fcgi and nginx on cpanel.  It worked well until i went over a certain amount of traffic at the same time.

I quickly replaced nginx with the varnish cpanel plugin which helped a little and caused the load to drop.

I also noticed that FCGI was running away with processes and helping cause the swapping.  Exchaning this for suPHP did help but i found the performance wan’t anywhere near as good.

As i am the only person on the server i have since moved to DSO which dropped my load average down to around 1 which is perfect for me.

The only problem being that dso runs as the apache user nobody:nobody.   as i wanted to change from super cache to w3 (as i’ve seen some stats indicating that w3 total cache can handle a higher load) i have had to go through sorting file permissions of each site so that the W3 plugin can write the cache.

playing around with APC , eAccelerator and memcached  i have found the best results are in using enhanced disk for my page cache and APC for the database, object and minify.  MY sites are now ready for any spike in traffic that can be thrown at them!

 

messing around with preg_replace….

I am probably trying to reinvent the wheel here but…..

I wanted to get the top 20 or so tags from a wordpress blog and to use the tags for a loop of 3 posts from each tag.

The only function i could find to get the most used tags was wp_tag_cloud

by taking it into an array i could get the top 20 tags.

$tags = wp_tag_cloud( array( 'number' => '20', 'order' => 'DESC', 'echo' => 'false', 'format' => 'array' ) );

I looped through this array using:

 foreach($tags as $tag)

unfortunately the wp_tag_cloud did not return a list of tag id’s for me to  loop through.

each $tag was in the format of a url,  i.e. <a id=”” href=”http://domain.com/tag/post_slug” style=””>tag name</a>

So i needed to extract data from this to find the tag.  i chose to extract the tag slug which would be in the url.

$tagslug= preg_replace(‘%<a .*? ?href=[“\’]([^”\’]*).*?>.*?</a>%i’, ‘$1’, $tag);

returned the url for me.  Unfortunately my regular expression skills are pretty poor and couldn’t work out how to extract the slug straight away using markers. (my university professor would not be proud.)

so i took the url and ran another preg_replace on it to get the tag slug

$tagslug = preg_replace(“/.*\.(com|gov|org|net|mil|edu)\/tag\/([a-z_\-]+).*/i”,’$2′,$tagslug);

This finally returned the tag’s slug for me,  I had a wee function called get_tag_id_by_slug i made so i called that.

$thetagid= get_tag_id_by_slug($tagslug);

which returned the tag id number for me, so finally i could use
$term = get_tag($thetagid);

to get the actual term to use in my wordpress loop

$new_query = new WP_Query(‘r_sortby=highest_rated&r_orderby=desc&posts_per_page=4&tag=’. $term->slug);
while ( $new_query->have_posts() ) : $new_query->the_post();

 

My function to get the id from the slug is:

function get_tag_id_by_slug($tag_slug) {
global $wpdb;
$tag_ID = $wpdb->get_var(“SELECT * FROM “.$wpdb->terms.” WHERE `slug` = ‘”.$tag_slug.”‘”);
return $tag_ID;}

 

After doing all this i decided that its all very well to automate things but some of my most used tags were very similar and i didn’t want a loop containing the same 4 posts over and over with a new title.  So in the end i just went with.

$tags=get_tags(‘include=7,8,11,30,45’);

and looped that!

DOH!

Flash Games

I have made a plugin for wordpress to display up to 200 flash games within your wordpress blog.

It is a relatively simple plugin that pulls data from my arcade website Lingolux flash games.

At the backend Lingolux uses a simple wordpress WP_Query loop to pull data from the site as specified by the plugin.
This allows the user to select the number of games and whether to display new games, top games, or both.

Although most blogs will cache the page themselves i did not want my plugin to overwhelm my website so i implemented a simple caching system in php.
I found the information here


";
exit;
}
ob_start(); // start the output buffer
?>
I placed the wp query here

This provided some simple caching of the backend.

The plugin also uses a simple lightbox to display the flash.
You can see the plugin in operation here and you can download it from the wordpress site here
Flash Games Page

SPL reconstruction

I think the 10 team league could work…. but only if they did something radical!

How about adopting The South American style system?

An “opening tournament” where each of the 10 play each other twice, a champion is declared.
Relegation wise, they could have 1 or 2 down 1 or 2 up (or playoffs whatever = extra tv money etc).

Then comes the “closing tournament” every team plays each other twice again and another champion is declared. If the same team wins twice then they are the “overall winners” but if you have 2 different teams then you get a huge money spinning “champions playoff” a game to decide who gets the champions league place. The the other european spots can be decided with the much the much touted playoffs based on league positions over the 2 seasons.

This would give the other teams more of a chance of winning the league as you don’t have to play the old firm 4 times a season, other problems that usually affect challengers (injuries, suspensions and squad size) don’t cause as many problems as each season only lasts half a year.

It would alleviate the huge economic hit of being relegated as you now have the possibility of being promoted twice a year.

It would also introduce the huge money spinner playoffs everyone wants.

TV still get their 4 old firm games a year and the fans get more of a chance of winning the league!

The idea of B teams should be scrapped.
It would be horrible to be stuck in a league with Ranger/Celtic reserves… i can’t imagine many Raith Rovers/Dunfermline/Falkirk/etc fans wanting to go watch their team vs reserves!
Placing them in regional leagues is pointless too… what benefit would they get out of playing milkmen and posties week in week out?
They need to reintroduce the reserve leagues and encourage the big teams to link up with smaller teams for year long loans for the young players who are 5th/6th choice at their current clubs!