Weekly Tweets for 2012-01-07

Posted in Tweets | Leave a comment

Weekly Tweets for 2011-12-31

Posted in Tweets | Leave a comment

Weekly Tweets for 2011-12-24

Posted in Tweets | Leave a comment

Taunting a frog with an iPhone

Posted in Videos | Leave a comment

Quick Fix for OpenX Redirect Loop

Last week I installed OpenX on my server to use for an upcoming project. After getting it installed and setup admin-side, I went and made sure the zones looked right on the project site. Chrome gave me an error that it was in a redirect loop.

It appears this is a very common problem with forum threads all around. The cause is that OpenX uses the same cookie name for both ad viewer tracking and admin logins, a cookie named OAID. Since OpenX is open source I could have dug through the code and either figured out why it was redirecting or changed the cookie name. But I wasn’t really up to that.

Closest thing I found online to a solution was to either clear cookies between using the admin side and checking the production site, or to use two different browsers. Neither a really good solution.

Came up with a better, and much easier, solution. Continue reading

Posted in Computers & Internet | Tagged , | Leave a comment

WordPress recent posts as JSON

For an update to one of my web projects I went looking for a way to get the recent posts as JSON instead of using the RSS feed. I personally find JSON much easier to deal with than RSS, so that’s the route I wanted to take.

Continue reading

Posted in Programming | Tagged , , | Leave a comment

days_ago function for PHP

Can’t take credit for all of this, but I also don’t remember where the code that I started with came from.

days_ago is a function that will take two dates and return a more human friendly version of dates. So if you pass today’s date and yesterday’s date it will return “1 day ago.”

Continue reading

Posted in Programming | Tagged , , | 1 Comment

PHP function to get first n words from a string

A handy little function for your bag of tricks. This PHP function will return a max number of words out of a string, or the whole string if it’s already shorter.

/**
 * Returns the first $wordsreturned out of $string.  If string
 * contains more words than $wordsreturned, the entire string
 * is returned.
 * @param String $string The string to check
 * @param int $wordsreturned Max number of words to include
 */
function shorten_string($string, $wordsreturned)

{
    $retval = $string;
    $array = explode(' ', $string);
    if (count($array)<= $wordsreturned) {
        $retval = $string;
    }
    else {
        array_splice($array, $wordsreturned);
        $retval = implode(' ', $array).' ...';
    }
    return $retval;
}

This probably could be made shorter, but I was in a hurry when I needed this and went for quick rather than clever.

Posted in Programming | Tagged , , , | 1 Comment

Weekly Tweets for 2011-12-10

  • Took one of my sites from a load time of 6.5+ seconds to 1.31s – stripped a social plugin, minifying, and CSS sprites http://t.co/AxYb5ha2 #
Posted in Tweets | Leave a comment

fsockopen / fgets very slow in PHP

I’ve been using a PHP class in a project that pulls a URL and then caches the result so it doesn’t have to get loaded again until it’s considered stale. Works pretty well, but every time it went out to get a fresh copy of a page it took forever.

I was using fsockopen and fgets to read the information. Pretty standard, and normally works for me. It wasn’t until I timed a request that I caught what was happening. The request was taking just over 15 seconds. 15 seconds happens to be the timeout on my web server. So the request was happening quickly, but waiting for the server to timeout.

One little line. That’s all that was missing. I had left out a header in the request.

Connection: Close

That was it. Added that to the headers that were sent and the request went from 15+ seconds to a few tenths of a second and all is well.

Nice that the actual fix only took about 10 seconds. Too bad that it took me half an hour of Googling to figure out that was the issue.

Posted in Programming | Tagged , , | 1 Comment