Tags

, , ,

Share it

We do a lot of support of OpenSource CMS’s at work, and one of them happens to be WordPress.

I recently thought it might be cool to have a bit more of a play with W3-Total-Cache as it is a plugin of choice to assist customer with scaling issues.

Since my blog is massively popular (not!), I decided to use the S3/CloudFront option, presented here.

Well it didn’t work.

Very sad face. All the tests were passing OK, but nothing was changing in the source of my pages.

Putting on my PHP hat, I jumped in and started writing little statements to print out variables and settings using a couple of my usual debug methods:


file_put_contents ("/tmp/gjc.txt", $buffer);
trigger_error('doing stuff', E_USER_WARNING);

It didn’t take me long to figure out what was going on, and it was staring me right in the face. A setting for Easy AdSense that had ads above the heading literally had them above the XML document type header.

This check if ($buffer != '' && w3_is_xml($buffer)) { was failing and not reporting anything anywhere, but because it was failing, it wouldn’t change anything.

I fixed up the ad placement, and sent in the below patch. Hopefully it helps someone else in the future.


--- Cdn.php.orig 2014-08-17 15:07:47.872901114 +1000
+++ Cdn.php 2014-08-17 15:07:30.029061393 +1000
@@ -242,7 +242,11 @@
*/
function ob_callback(&$buffer) {

- if ($buffer != '' && w3_is_xml($buffer)) {
+ if ($buffer == '') {
+ trigger_error('Buffer is empty.', E_USER_WARNING);
+ } else if (!w3_is_xml($buffer)) {
+ trigger_error('Buffer is does not appear to be XML.', E_USER_WARNING);
+ } else {
if ($this->can_cdn2($buffer)) {
$regexps = array();
$site_path = w3_get_site_path();