Transients are a great tool for the WordPress developer. They allow you to easily save temporary data with their own expiry time – simply pass the transients data into the easy-to-use API and it will sort everything out for you. Caching made simple.

Unfortunately, using transients is not without its downsides and recent experiences have shown a couple of issues that any developer should be aware of.

But first I need to explain how transients work.

Transients were not introduced until version 2.8 of WordPress and make use of the WordPress options table (usually named wp_options) to store their data. There aren’t enough fields in this table for the transients to be stored as one record so, instead, it’s split over 2.

Each transient is given, by the developer, a unique name. This is prefixed by either _transient_ or _transient_timeout_ and used as the option_name field. The option_value field is the transient value and the expiry time respectively. You can also store and access network wide transients and these have _site further prefixed to the beginning of the transient name.

So, let’s say you create a transient named ‘test’. Two records will be added to your options table. The first record will be named _transient_test and will have a value of whatever you wished to store in the transient. The second record will be named _transient_timeout_test and the value will be the timestamp of when it expires.

The exception to this rule is if you create a transient that is not set to timeout. In this case only the first record will be created.

If you were creating a network-wide transient then the names would be  _site_transient_test and _site_transient_timeout_test.

How to use Transients

There are 3 simple commands – set_transient, get_transient and delete_transient. The latter two have just one parameter – the transient name.

set_transient, in comparison, has 3 parameters – the transient name, the contents to store and the timeout (in seconds). Set the timeout to 0 for it to never expire.

set_transient and delete_transient both return true or false, depending on their success. get_transient returns the transient content or false if it wasn’t found.

Network-wide transients are handled by the commands set_site_transient, get_site_transient and delete_site_transient. All parameters and return values are as the non-network equivalent.

Problem #1: Transient Name Lengths

The option_name field in the options table has a record length of 64 characters. So, taking into account the prefixes added to the transient name, a transient name can only be a maximum of 45 characters (or 40 characters for network transients). The problem here is that WordPress doesn’t check. It doesn’t fail either – it creates the transients but simply truncates the name. And because each of the transient record pairs has a different length prefix then they each end up with a different name – this means the transient can’t be retrieved.

The Solution

  • WordPress are aware of this and a Trac ticket is open to prevent this from happening. I have updated the ticket myself to ensure they’re aware of the 40 limit for network transients (suggesting that the limit should be a uniform 40 to avoid confusion).
  • The Codex already makes mention of the 45 character limit for set_transient but didn’t mention the 40 limit for set_site_transient. I have now updated the appropriate page to reflect this.

Problem #2: Housekeeping

When you attempt to get a transient and it’s expired WordPress will automatically remove that transient from the table. However, if that transient is never accessed again then it will not be removed.

Why would this happen? Let’s say a plugin uses transients to cache some data. The transient name may be a unique name which represents the options requested – that way, if the user changes the options the, now incorrect, cached data is not used. However, the old transient will never be re-accessed.

To give you an idea of the scale of this I’ve heard one user has over 250,000 transients in his database which have expired.

The Solution

Conclusion

Transients are a powerful and useful tool for the WordPress developer. However, be aware of their limitations and tread carefully!

I’m one of those who are guilty of writing plugins that generate transient names longer than the limit and of generating transients that won’t be accessed once they’ve expired. Now I know all of the above the way I use the transient system has changed.

A recent Tweet by Richard Taylor, editor of the BBC tech show Click, got me annoyed. In it he directs readers to a video of him giving various tips, based on “years of experience”, on how to save the battery in Smartphones and tablets.

It got me annoyed because it’s no different to the lists you find elsewhere, and they’re  not any good either. Don’t get me wrong ,tips such as “turn off Bluetooth” do save battery, but what is the point is buying a device such as a Smartphone to then turn off the very features that make them “smart”?

So, here are my recommendations.

Understand the Cause

You’ll achieve nothing if you don’t understand what is actually causing your battery drain. Often it can be an app and you may want to re-evaluate your use of it to save battery.

Head to Settings -> Battery (that’s correct for Jellybean but your options may vary). Here you can view your current battery state and, particularly, what’s draining your battery.

When I had a Samsung Galaxy S2 the display was the top drain. For my Nexus 4 it’s  way down the list.

Understanding all of this can give you a better idea of what needs most attention and what, let’s be honest, is hardly worth bothering with.

Switch Off Smartly

Other than apps, big users of the battery are usually the screen, Bluetooth, GPS, WiFi and sound.

So, unlike other recommendations to just turn these off it’s perfectly possible to not cripple the capabilities of your phone but still disable them as required. Obviously if there’s a function you don’t ever use – such as Bluetooth – then it does make sense to switch it off. Otherwise, you need to be smarter about it.

There are a lot of apps that allow you to set profiles – these can switch automatically depending on your environment, whether the detection of a particular WiFi router or a Geo-location.  Or there are simpler ones – apps that simply mute your phone overnight.

When I’m in the car I use a specific Car Dock app for playing music through my in-car stereo via Bluetooth. One of the clever things this does, when launched, is activate my Bluetooth and deactivate my WiFi (I’m in the car after all). Once I exit out from it it reverses this – I only normally use Bluetooth in the car so this makes the most sense.

Charge Properly

When I had my Samsung Galaxy S2 I had it sat in a powered dock at work. I’d take it out to go to a meeting and plonk it back in when I returned. In no time at all the battery was wrecked.

I’ve found charging the phone only when needed is the best approach – try not to let it go flat but charge it to full.

Conclusion

All of the above means I don’t have settings un-necessarily turned off. My WiFi, sound, NFC, GPS are all on. Only my Bluetooth is usually switched off. Basically, my Smartphone is actually smart.

But does it work? The following suggests it does…

Screenshot_2013-04-04-14-46-06

Sony Wireless Keyboard - angled viewThe on-screen keyboard on the PS3 isn’t too bad but sometimes using the controller can be slow and cumbersome – particularly for long messages.

As a server administration for my Battlefield clan I now often have to message people if I’m intending to “kick” them so that they know why (usually to allow clan members on, sometimes because they’re being a douche). So, a “proper” keyboard was a good idea.

As I’m sitting the other side of the room a wireless option was always going to be best but reviews of using “standard” Bluetooth keyboards on PS3′s were always poor, due to regularly dropped connections. I’d be cynical to suggest this was something done by Sony to promote their own kit ;)

But as its turns out, Sony’s own Bluetooth keyboard has no such connection issues. Pricey, though, it is – £40 from Amazon, for instance.

However, you really do get what you pay for – the keyboard is excellent. It’s compact (about the same size as a laptop keyboard), made even more so by a lack of edge around it – I’ll explain this further in a short while. The keys have excellent travel and a good, standard layout. They’re very square but not spaced like “scrabble tile” keys are. The top row of keys are function keys but by pressing these alongside a “function” key then these can perform PS3 controller actions – e.g. the square button.

All the normal computer keys are here so it can be paid with other devices as well – I tried it on MacBook for example and this worked fine. However, be aware that the keyboard only remembers one pairing at a time, so regularly using it on both the PS3 and another device will become a pain.

In the middle of the keyboard is a pointing stick instead of a trackpad and there are two thin “mouse buttons” in front of the space bar. This means that it truly can be used as a multi-functional keyboard with different devices.

As I was saying before there is no bevel around the keyboard – the keys go edge-to-edge – with the exception of the bottom. A small ridge exists beneath the bottom row of keys, housing the aforementioned mouse buttons and, in the corner, the power button. Next to it is a status light. The lack of any kind of edge is about the only issue with the keyboard as picking it up and, particularly, handing it to someone it tricky without accidentally pushing down buttons as a result. But, naturally, it keeps the keyboard size to a minimum.

The keyboard works with 2 AA batteries (supplied) which are placed in a raised section on the rear of the underside – this section then props the keyboard up at the right angle for typing. Rubber feet prevent the keyboard from slipping about.

When initially setting it up for some reason I couldn’t get it to power on. This suddenly resolved itself and I’ve had no problems since.

The keyboard comes in a slimline box which is barely larger than the keyboard itself – a good bit of reduced packaging which is always welcome.

Summary of Sony Wireless Keyboard

An excellent quality keyboard which can be paired to pretty much anything with Bluetooth. Superb in use on the PS3 it’s only problem is the lack of bevel making picking up difficult, particularly when in use.

But that’s a minor point – if you can afford to spend £40 on a keyboard then it’s a worthy purchase.

Star Star Star Star Star


Reviewed by David Artiss on 1st May 2013.

CollageIt Pro is an automatic and easy to use collage maker on Mac OS X & Windows. Making collages is as easy as 1-2-3 with only 3 steps…

  1. choose template
  2. add photos & customize
  3. export collage

Other features include

  • Various layouts and diverse templates.
  • Easily personalize collage by cropping, adjusting photo number, photo space, page margin, rotation, sparse, and so on.
  • Save collage as an image file; set as desktop wallpaper; share through Email; or print it out.

To celebrate Mothers Day in the US we have 20 licences for CollageIt Pro to give away – 12 for Windows and 8 for OS X. Below are 2 entry forms – 1 for each licence type. Simply use Facebook and/or Twitter to enter.

Find out more about it CollageIt Pro from their website, Facebook page or Twitter account.

Competition promote on ThePrizeFinder – UK Competitions

Windows Licence

Windows licence giveaway

Mac Licence

Mac licence giveaway

Top
%d bloggers like this: