Created
February 1, 2011 15:24
-
-
Save methodin/806001 to your computer and use it in GitHub Desktop.
Common functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Log to a file | |
function dump($data,$file='/var/log/mylog.log') | |
{ | |
file_put_contents($file, $data."\n", FILE_APPEND); | |
} | |
// Use some locking for a cron job | |
function lockit($name) | |
{ | |
$file = '/tmp/'.$name.'.lock'; | |
$fp = fopen($file, 'w+'); | |
if(!flock($fp, LOCK_EX | LOCK_NB)) { | |
dump('Could not get lock'); | |
exit(-1); | |
} | |
return $fp; | |
} | |
// Handle creating a Mongo instance | |
function mongo() | |
{ | |
$connection = new Mongo(DB); | |
$db = $connection->databasename; | |
$db->authenticate(DB_USER,DB_PASS); | |
return $db; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment