file_get_contents

Ames and I had a great move from Gainesville to Columbia! Everything between packing and closing when smooth, and although we’ve been working really hard on fixing the place up, we’re really happy with our first home. In fact, I wanted to spend my free time before work this morning finishing up my do-it-yourself post on removing popcorn ceilings, but I when I checked my gmail, I had over 100 comment spams to delete from mister aaa@aaa.com. If you have a Movable Type blog, you probably know him well…all he ever says is “Interesting!”, “WOW Nice Site!” I’ve had problems from him since before I moved to Dreamhost, but since then I haven’t been able to get MTBlacklist working to block him. Well, after deleting all those comments, I was pretty set on getting that fixed. Just as I figured, it was a permissions issue. After chmodding some mt files back to 755, I was up and running again with my spam filters, and just for good measure, I installed the latest version of Blacklist as well.

Since I was already in troubleshooting mode, I decided to tackle my Smart 404/Search problems. I kept getting “URL file-access is disabled in the server configuration” error whenever I tried to search or go to a non-existing url. I knew it all worked before, so I started snooping through my code and eventually figured out that Dreamhost has disabled the PHP option allow_url_fopen...which in turn kills file_get_contents. Argh! Fortunately, they've setup a workaround using curl.

I know Mike Davidson must have fixed this issue on his site because he's a dreamhost user too, but I didn't find anything on the related post or comments, so if you've followed his method too, here's a fix:

In your 404.php page, change:

$full_page = file_get_contents($full_search_url);

To:

$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $full_search_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$full_page = curl_exec($ch);
curl_close($ch);

...and in your search.php page, change:

$search_results = implode('', file($link));

To:

$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$search_results = implode('', array($file_contents));

How much fun is THAT!?!? I don't think I know anyone who this applies to, but I thought I'd write it up anyway in case I ever need it again. Hopefully I'll get that popcorn removal post up sometime next week, cause I know you're ALL dying to get rid of the popcorn ceilings in your houses.


About this Entry