Skip to content

Instantly share code, notes, and snippets.

Last active Feb 16, 2018
What would you like to do?
Simple php page to serve as a log for homey without the need for the actual simplelog app
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$dir = 'logs';
//here you set the time format the current setup will show YYYYMMDD HH:MM:SS
//please see the php date() documentation to change
$current_time = date('Ymd H:i:s' );
// if there is no "e" (entry) just type tywo dashes
$txt = " -- ";}
$txt = $_GET['e'];}
//if no "l" (log) is specified use the default log.txt
$log_name = 'logs.txt';}
//else use the logname+.txt as filename
$log_name = $_GET['l'] ;}
echo $current_time;
// create new directory with 744 permissions if it does not exist yet
// owner will be the user/group the PHP script is run under
// but thuis does not work properly yet, YMMV .
// run "ps aux | grep httpd" to see under which user the http daemon runs
// then make the logs sub-directory
// sudo chown phpuser:phpuser logs //phpusr depends on the user httpd runs under
// sudo chmod 755 logs
if ( !file_exists($dir) ) {
$oldmask = umask(0); // helpful when used in linux server
mkdir ($dir, 0744);
// set variables and write/add to file
$txt = "[".$current_time."] ".$txt ;
$myfile = file_put_contents($dir."/".$log_name.".txt", $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
$mybackup = file_put_contents($dir."/".$log_name.".bak", $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment