Mostly about my amusement

Tag: WordPress (page 12 of 13)

Adding Slimstat to WordPress

Slimstat thumbI run this web site as a hobby but I still like to have tools to check how the site is doing. Slimstat is a tool that I use because it captures things like search strings, referers, etc. It’s like Google analytics but more local.

For WordPress there is a useful plugin that adds Slimstat to the dashboard. My advice to people is to use the plugin as it is fire and forget.

I don’t listen to my own advice 🙂 so I prefer to add Slimstat outside of WordPress by adding a few lines to the wp-config.php like so:

// Jan added Slimstat
$ip_jan=$_SERVER['REMOTE_ADDR'];
$url_ref=@$_SERVER['HTTP_REFERER'];
if (($ip_jan != "24.46.186.255" ) or ($ip_jan != "64.233.178.136")) {
   if (!(preg_match("/translate.google.com/",$url_ref))) {
      @include_once( "/srv/www/slimstat/inc.stats.php" );
   }
}
/* That's all, stop editing! Happy blogging. */

I am not a programmer and my PHP is horrible. I add the code to wp-config.php because it gets included every time and I don’t have to modify the theme. Putting it there also means when I upgrade the theme or WordPress version it will get preserved from being overwritten.

I put the if statements in there because I want to exclude from logging website requests from a Google address and from my own IP address. I use Angsuman’s translator plugin and exclude anything that is refered from translator.google.com. If someone hits a web page with /post-slug/es/ (for the spanish version) then I want to see that URL and not the ones that the machine translator hit.

Setting up Slimstat is easy as pie. I put the slimstat on a HTTPS portion of my web page, used .htaccess to password protect the URL (for no real reason other than I can) and I get easy stats available to me without logging into WordPress.

WordPress 2.2 is out

WordPress 2.2 is out and has at least one really useful feature that I’ve already used.

I backup my blog software and database on a nightly schedule. The whole works, database and files gets copied to my backup server on a VPS.

Testing the backup is a pain since the database points to the real URL and hostname. Now with 2.2 you can override the site url and wordpress home with these two lines in your wp-config.php file:

define(‘WP_SITEURL’, ‘http://www.sample.com/wordpress’);
define(‘WP_HOME’, ‘http://www.sample.com’);

I created a new backup and restored it on my VPS server. I made that change to the wp-config.php file to point to the name and location of the backup server. Now all the links and administration work fine referencing the real hostname.

See http://codex.wordpress.org/Version_2.2 for more information. This feature lets you test your database on another server and play around without impacting your real blog.

XHTML 1.0 Strict and WordPress themes

WordPress themes are usually either XHTML 1.0 Transitional or XHTML 1.0 Strict. The first line of the generated web page has the Document Type Definition (DTD) sent to the browser to define which.

My main theme that I use FastTrack, was defined as transitional. Just for kicks I changed it to strict and figured I would use the W3C validation service to identify what needed to be changed to make it validate.

I did not have to change much. The built in TinyMCE editor produces img tags that are not XHTML 1.0 Strict compliant. For example an image will have the tag defined as

<img src=”http://blog.dembowski.net/wp-content/costco-harmony-720.jpg” title=”Logitech Harmony 720″ alt=”Logitech Harmony 720″ align=”right” hspace=”5″ vspace=”5″ />

The attributes align, hspace, and vspace are valid XHTML 1.0 Transitional but not strict.

In order to make it valid for strict I had to lose those attributes. In strict this is valid:

<img src=”http://blog.dembowski.net/wp-content/costco-harmony-720.jpg” style=”margin: 5px; float: right” title=”Logitech Harmony 720″ alt=”Logitech Harmony 720″ />

The align attribute is not valid for <p> tag either, this requires another replacement with a style= statement.

In the theme I replaced one that was using <p align=”center”> with <p style=”text-align: center”>.

The last thing was to change strike through and underline. I used to put in the post via the code tab <strike>text</strike> which is not valid in strict. Neither is <u>underline</u>. I replaced that with <del>text</del> to have a line through the text and <ins>text</ins> to get underline.

I’m not particularly concerned about XHTML compliance. This and playing with CSS entries is just part of my learning and understanding how this all works.

Easy server upgrade

I gave up on running my blog on a VPS. It was just too problematic and I got tired of trying to get it working well. So I opted to put the blog on my old basement server.

My old basement server was a Dell PII 450 MHz machine with 256 MB of RAM. It was a good example of how Linux can extend the life of your hardware. It works well as a Internet gateway and mail relay but for serving dynamic web page pages it was a little slow.

When I purchased my XPS 700 monster I shelved the old PC. That one was a P4 3.2 GHz with 1 GB of RAM. For running Linux it’s great.

At first I was bent on getting a fresh install but I ended removing the old hard drive and putting it into the new server. The worst that I had to deal with is the network interfaces were named wrong (one was coming up eth2).

After a little searching I found the file

/etc/udev/rules.d/30-net_persistent_names.rules

and fixed the names from

SUBSYSTEM==”net”, ACTION==”add”, SYSFS{address}==”00:0c:5a:b4:b2:d2″, IMPORT=”/lib/udev/rename_netiface %k eth2″

to

SUBSYSTEM==”net”, ACTION==”add”, SYSFS{address}==”00:0c:5a:b4:b2:d2″, IMPORT=”/lib/udev/rename_netiface %k eth0

The udevd daemon is great but I hardly ever looked at it.

Page generation on WordPress went from 1.7 seconds on the old server to 0.234 seconds on the new one. That’s not too bad an improvement and all it cost me was a server that I was using as a door stop.

eAccelerator for Opensuse 10.0

Updated: I bumped the version from 0.9.5 to 0.9.5.1.

The source RPM for 0.9.5.1 can be found here.

The 32 bit compiled version can be found here.

I no longer have access to a x86_64 opensuse installation but running this command:

rpmbuild -bb php5-eaccelerator-0.9.5.1-1.src.rpm

should create them on your system.

——————————-

I wanted to add APC or even XCache but found that my PHP version 5.0.4 was not supported. Changing to 5.2.1 did not really seem to work well for me and some plugins did not work. So I went back to the default updated opensuse 10.0 packages.

The PHP cache software eaccelerator 0.9.5 does work with php 5.0.4. In fact sometimes it speeds up php by almost half.

The opensuse 10.0 source rpm I put together can be found here. I built the .x86_64.rpm and put a copy here. The src.rpm will figure out where to put the extension so if you do a rpmbuild on the src.rpm on another opensuse which has php5 installed it should work.

The spec file has some build requirements, most of which can be commented out I am sure. I built it with

configure –enable-eaccelerator=shared –with-php-config=/usr/bin/php-config

I put the eaccelerator.cache_dir in /var/spool/eaccelerator and made that directory part of the package.

Inside the footer of my theme I put

<!– <?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds. –>

The timer shows that pages were taking 1.3 seconds or more to generate, sometimes longer.

With eaccelerator I get 0.628 seconds or so.

I also keep

define( ‘ENABLE_CACHE’, true );

in my wp-config.php right below the line that reads define (‘WPLANG’, ”);.

This caches database information such as categories etc. I turned it off and the frequent hitting of my mysql tables introduced a big delay in response time.

Next up will be to tune my mysql settings.

Webserver issue solved

I will not turn off “define(‘ENABLE_CACHE’, true);” again.
I will not turn off “define(‘ENABLE_CACHE’, true);” again.
I will not turn off “define(‘ENABLE_CACHE’, true);” again.

Now I will repeat that 1000 times on the black board and never do that again.

Webserver problems

I have been having some weird response times from my WordPress installation. I’m running Opensuse 10.0 which comes with PHP 5.0.4.

PHP caches like APC and XCache don’t work with 5.0.4. I can’t just upgrade the distribution since a) this is a VPS and only 10.0 is offered and b) that would be over the top.

First thing I tried was add the software repo at http://software.opensuse.org/download/server:/php/SUSE_Linux_10.0/. I ran yast, checked php5 and poof it installed. Now I was at php 5.2.1. I kept track of the RPM’s and kept the replaced ones in case the bad thing happened.

Both cache apps are built and installed the same way

Extract the tar.gz file
phpize
./configure –some-options
make && make install

And that’s it. Some php5.ini modification and I’m in business.

APC compiled but blew up php in strange ways. Xcache installed and worked well. Even came with an admin page for checking the stats.

WordPress and some of my plugins don’t seem to like 5.2.1 and even with Xcache I was not seeing an improvement. The problem is that the initial response from the web server is 3-10 seconds to get data. I’ve got WP-Cache installed to see if subsequent page loads are faster (they are) but I think the problem is either my VPS or the network.

I rolled php back to 5.0.4 and removed Xcache. Hopefully the problem will sort itself out.

RSS feed and Tarski Links Widget

Sidebar_arrangementtThe RSS feed on this web site became broken and I tracked it down to the Tarski Links widget. I use the Tarski theme as one of my two themes. The regular links widget looks awful so the Tarski theme guys came up with a replacement that looks pretty good.

But it breaks my RSS feed. Enabling that plugin somehow caused a blank line to be inserted before my feed. I did not bother to report it to the Tarski or WordPress forums since I am sure that I somehow made a mistake when I copied the code.

While I was playing with the code and confirming that I am not a programmer, I realized that I wanted some of the widgets to go away when people look at a post. I came across Otto’s page and installed the Executable PHP Widget.

Before widgets became available, I would add to the sidebar.php file the functions I wanted to display, like the weather icon. Being able to run PHP code in a widget is pretty useful.

I removed the Tarski Links widget and copied the following code lifted from links.php in the Tarski theme. This was pasted into the PHP Code widget.

<?php
if (is_home()) :
echo “<div class=”bookmarks”>n”; wp_list_bookmarks(’category_before=&category_after=
&title_before=<h3>&title_after=</h3>
&show_images=0&show_description=0′);
echo “</div>n”;
endif;
?>

And poof the Blogroll links look good, my RSS feed works and I am happy. On the home page it appears, any other page it doesn’t. I repeated this a couple of times with other items on my sidebar.

The correct way would be to code this all as a widget, and include a check mark for “show on home page only” but I’m not a programmer and this works for me.