Quick Tips

Quicktip: Read from stdin in PHP

0

Quicktip: Add conditionals in a WHERE clause

0

Quicktip: Simple File Based Cache Mechanism in PHP

Simple, yet effective enough, this is all the code I used to create caching for a feed retrieval to speed up subsequent requests.

Enjoy!


< ? php
/**
* @param string $uniqID - Anything that would be unique to what you are caching (url/database query)
* @param integer $expireSeconds - How old is too old that we refresh the cache
*/

function _getFromCache($uniqID, $expireSeconds) {
$uniq = '/ /’.md5($uniqID);
if (file_exists($uniq) && time() – filemtime($uniq) < = $expireSeconds) {
return ' ($uniq)’;
}
$somethingToCache = ‘($uniqID)’;
file_put_contents($uniq, $somethingToCache); //You will want to implement __toString() if this is an object or maybe you can just serialize it
return $somethingToCache;
}

0

Quicktip: Random string in unix

nas:~# echo `</dev/urandom tr -dc A-Za-z0-9 | head -c8`
8vxeuIfi
0

Quicktip: Check if a class constant exists in PHP

2

Retrieve D-Link Router WPA Password via Firebug

Well I’ve done it a million times, I forget my WPA password and each time a new device comes along I have to change it for them all. Well no more!

Read more

0

Automating MySQL Database Backups on the Command Line via mysqldump

Are you tired of manually running backups when you remember to?

If you are running your own server, or have access to the shell and cron jobs this tip is for you!

First off for a better understanding of mysqldump check out the MySQL reference manual. All mysqldump really does is output the necessary queries to rebuild your database to the current state it is at when run.

First I’m going to create a test database and some tables as examples:

Read more

2