Blog posts tagged "bug"

Google Map Anomalies

March 11th, 2005

Google Maps is very cool, on so many levels, its hard to know where to start (definitely the long wake), but it does have some odd quirks.

Check out this map of the booming metropolis of Roger Williams National Park between Pawtucket and Cranston. (hint for those who haven’t lived in the Ocean State, Rhode Island seems to have misplaced it’s capitol.)

update: you now have to zoom out one notch to see Providence disappear.

Tagged: Uncategorized , , ,

PHP 4.3.2, fread(), network streams, and Magpie

June 25th, 2003

At long last we come to the end (hopefully) of the MagpieRSS and PHP 4.3.2 saga, the good guys win, the bad guys unforunatley got away and will live to program again, but for now all is peaceful. Look for MagpieRSS 0.5.2 later this evening.

When using fread() on a network stream, it must be called in a loop

When reading from network streams or pipes reading will stop after a packet is available. – PHP Manual: fread

The documentation goes on to say, “when reading from network streams or pipes, you should collect the data together in chunks”. There, could it be any clearer!

Migration Headache

Why yes, yes it could. You see, it didn’t used to be like that. I’m not sure how long the documentation has been changed, but until recently fread() was quite content to read past the end of a packet until you had all the information you asked for. Migration is complicated by the fact that this new behaviour happens very very quietly, and seemingly sporadically. You would never know anything had changed until your XML started showing up mangled causing only the first item in an RSS feed to show up, or your gzip encoded data was delivered improperly formatted causing gzinflate(): buffer errors (to choose 2 hypothetical example).

And then of course there is the, ahem, questionable “example” of using fread() with a network socket one finds in the fread documentation.. (more on that later)

Steve Minutillo

But first, I’d like to go on record and say Steve is the genius, and a very nice person who figured this all out. I was still stuck swearing at expat, and then on a clue from Steve I was swearing at PHP’s bundled zlib. Neither of whom were to blame. It was Snoopy’s old style fread() usage, compounded by my gzip encoding hack. (Here is a patch to make the upstream Snoopy work with 4.3.2)

Now Back to Trashing PHP

Okay, what the hell is up with that example in the manual? We’re going to play a game, called “how many really really egregious bugs can you spot in this code”. No, poor style doesn’t count as a bug (but icky C inspired examples are a perfectly valid reason to stake someone over an anthill)


<?php
$handle = fopen ("http://www.php.net/", "rb");
$contents = "";
do {
    $data = fread ($handle, filesize ($filename));
    if (strlen($data) == 0) {
        break;
    }
    $contents .= $data;
}
fclose ($handle);
?>

I count 2, plus a minor one. And while I’ll be the first to admit PHP is not my best language, can someone tell me what is wrong with the much simpler, or are they just trying to trip people?


while ( $data = fread($handle, 10240) ) {
    $results .= $data;

}

So yeah if you’ve upgraded to 4.3.2 and you’re seeing cropped data, make sure you (or the library you depend upon) has been updated for the new, stricter fread regime.

Tagged: Uncategorized ,

Magpie, PHP 4.3.2 Memory Error, an Update

June 25th, 2003

Steve tracked down the root of the problem that is causing MagpieRSS to run out of memory after upgrading to 4.3.2. It lies in my (apparently dodgy) patch to Snoopy to add gzip support.

Temporary Solution

To turn off gzip encoding (and thereby avoid this bug) add:

define('MAGPIEUSEGZIP', false);

to the top of your script.

Explanation

After much hair pulling trying to get gzip encoding working in PHP, I found this magic recipe in comments attached to gzencode:

$results = substr($results, 10); $results = gzinflate($results);

Seems you had to strip off the gzip header to make it work. This was confirmed when I found Simon’s httpClient.

Apparently this is changed in 4.3.2, and stripping the first 10 characters leads eventually (through a yet untraced path) to an out of memory error.

Next Steps

Does anyone have any info about this? Any suggestions on a good way to support 4.3.2 and pre-4.3.2 PHPs? Gzip encoding really isn’t an optional feature in a modern aggregator, so turning it off is a short term solution.

Update 6/25 2:16

Okay, so I’ve got PHP 4.2.3 locally now (via Marc Liyanage’s excellent package), and I’m seeing similar behaviour. I don’t actually get an out of memory error, but I can see memory usage spike (with iPulse) and I get a warning about a gzinflate buffer error. Unforunately removing “$results = substr($results, 10);” does not fix the problem for me. So currently the only solution is to turn gzip encoding off :(

Curiouser and Curiouser

So removing the substr() call changed the error message form “gzinflate(): buffer error”, to “gzinflate(): data error”. However only for certain websites! Files served with gzip encoding from some sites (like mine) work, but from others, it doesn’t. Ack.

Tagged: Uncategorized , , ,

Magpie GZIP Bug

May 30th, 2003

MagpieRSS 0.5 can fail without errors when fetching a RSS feed using GZIP encoding if your PHP doesn’t support gzinflate() (i.e. it hasn’t been built with --with-zlib)

As of 0.5 sends an “Accept-encoding: gzip” header by default when fetching RSS files. You turn this feature off by adding define(MAGPIEUSEGZIP, 0) to the top of your script.

A patched version of the locally maintained extlib/Snoopy.class.inc that checks function_exists(gzinflate) is available in CVS. This fix seems to work, I haven’t had a chance to test it widely. It is a busy week, but I’ll try to have a final fix, and new version out in the next couple of days.

(sidenote: It seems silly to fork Snoopy, and give it a new name over one minor change like adding gzip support however development on Snoopy has stopped and its confusing this maintaing a local version because I don’t want to imply there is a bug with the real Snoopy, just my version. What do you think?)

Tagged: Uncategorized , ,