[PHP] PDO Function - Pastebin.com
I think I may have just simplified PDO into the ground… It could use a little error catching but you can add that yourself.
I think I may have just simplified PDO into the ground… It could use a little error catching but you can add that yourself.
So many side projects, so little time :( where to get started
This is a nice little snipet that I use when serving dynamic images so the client will cache them properly. It uses a 304 Not Modified header to tell the client to not re-download the file. This mostly saves on TCP overhead however a connection must still be made to the server. I’m sure that somewhere out there is a header to make it so the client won’t even send the request in the first place see edit.
$info = $result->fetch_assoc();
// They have the current version
if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == strtotime($info['updated'])) {
header('Last-Modified: '.gmdate("D, d M Y H:i:s", strtotime($info['updated'])) . " GMT", true, 304);
exit();
// Sent them the file
} else {
// Headers
header("Content-type: image/jpeg");
header("Last-Modified: " . gmdate("D, d M Y H:i:s", strtotime($info['updated'])) . " GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", strtotime(time() + 3600) . " GMT"); # 1h
header("Cache-Control: public, maxage=3600"); # 1h
header("Content-Length: ".strlen($info['image']));
echo $info['image'];
exit();
}
The only issue with this code is 99% of the server side work is alredy done. If it isn’t a mission critical image you can do this at the top of the file instead to save a lot of back end time.
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
header('Last-Modified: '.gmdate("D, d M Y H:i:s", strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) . " GMT", true, 304);
exit();
}
Edit: Changing Cache-Control to public will make the browser just send a hello packet and not wait for a reply before showing the photo.
Apple has lost a visionary and creative genius, and the world has lost an amazing human being. Those of us who have been fortunate enough to know and work with Steve have lost a dear friend and an…
Just finished Bioshock 2 and loved it… a little shorter then 1 but not by much. Still has just as many twists and turns along they way but I don’t think anything can top the firsts at 50%. The moral choice seams mostly irrelevant but I need to do some more research on it. Also the addition of achievements on Windows kind of gave it away that I was almost at the end of the game.
Playing around with Seesmic Desktop. Other then being a Silverlight app it’s not to bad.
This week the FBI launched an online document archive that they’re calling The Vault.