bug in PHP API, with fix attached
Thu, 4 Dec 2003 00:15:33 +1100 (EST)
Content-Type: text/plain; charset="iso-8859-1"
The PHP API _load_items() function reads in blocks of 1024 bytes. By
coincidence, I was testing with a message that caused the "\r\nEND\r\n"
terminator to fall across a 1024 byte boundary. Usually this is no big
deal, but in my case, the part in the first block was "\r\nEND" and in the
second block it was just "\r\n". Any empty line is skipped by a continue
statement without any further processing, leading to another call to
socket_read() and hence causing the client to block indefinitely.
The patch is to check if it is near the end, and to read slightly more
than 1024 bytes if it is.
Content-Type: text/plain; name="mc_phpapi_block_boundary.diff"
Content-Disposition: attachment; filename="mc_phpapi_block_boundary.diff"
RCS file: /cvsroot/wikipedia/phase3/includes/MemCachedClient.inc.php,v
retrieving revision 1.3
diff -r1.3 MemCachedClient.inc.php
> // if we're almost at the end, read the rest, so
> // that we don't corrupt the \r\nEND\r\n
> if ($bytes_read >= $len)
> $lastbit = socket_read($sock, $len - $bytes_read + 7, PHP_BINARY_READ);
> $line .= $lastbit;
> $buf .= $lastbit;
> $bytes_read += strlen($lastbit);
\ No newline at end of file