Thursday, October 29, 2009

read the last line of a file in PHP

If your not a gh33k just move along.
move along, this is not the post you are looking for.

Had a hard to track down bug today where some code that was supposed to return the last line of a log file failed - the logs had recently been rotated and the new file had no lines in it yet. I modified it to create a pointer to the beginning of the file and break out of the infinite loop if the pointer cursor ever gets back to the beginning of the file. With a few minor changes it will work in C C++ C# or Java as they all have something similar to fseek, ftell fclose etc



/**
*
* Reads the last line of a, presumably large, logfile
* without loading the whole file into memory
* Safe to use for 0 or 1 line files
*
*
* @param string
* @return string
*
*/
function readlastline($fileName)
{

$fp = @fopen($fileName, "r");
$begining = fseek($fp, 0);
$pos = -1;
$t = " ";
while ($t != "\n") {
fseek($fp, $pos, SEEK_END);
if(ftell($fp) == $begining){
break;
}
$t = fgetc($fp);
$pos = $pos - 1;
}
$t = fgets($fp);
fclose($fp);
return $t;
}

Thursday, October 22, 2009

Rock Climbing

Climbing1
My mad french friend has returned from Europe so last night we met up again for a climb.
Today my fingers feel like an arthritic old mans.
It always amazes me how tenuously small the little features on a rock wall can be yet we are still able to get purchase and climb steep and run out cliff faces, in climbing parlance steep = overhung, top photo. I'm going to try and get some of the slide film I took in Thailand 20 years ago scanned digitally. Hopefully the picks will be as good to laugh at at these of my skinny arsed youth. In the case of the last three photos here you can see my skinny arse in all its out of focus harness warped glory as the picks were taken when I climbed the last pitch of the three sisters naked.
Climbing12
Climbing9

Friday, October 09, 2009

Political interest.

I used to date one of these people, unfortunately she did not look like Patricia Patersen, Hajnal Ban or "Kate Ellis".

Who do you think and who would you date?

Thursday, October 08, 2009

Guess Her Muff hits 1000 posts

That's a lot of muff

http://guesshermuff.blogspot.com/

:-)