Commit 241b2fb3 authored by haemmer's avatar haemmer

Access log now uses flock for logging

parent abf0f83e
......@@ -382,7 +382,8 @@ Releases with a version number X.Y.Z usually are bug fix releases whereas
releases with a version number X.Y introduce new functionality.
1.14.2 - IDProvider.conf.php and config.php are not overwritten anymore by upgrades
- Logging to Syslog now works properly
- Logging to Syslog now works properly and is more consistent
- Access log now properly locks file
- Unknown category is not shown anymore when there is no other category
- Namespaces are now taken properly into account when parsing SAML2
metadata. Thanks go to Olivier Salaün for reporting this issue and
......
......@@ -479,20 +479,29 @@ function logAccessEntry($protocol, $type, $sp, $idp){
// Let's make sure the file exists and is writable first.
if (is_writable($WAYFLogFile)) {
// In our example we're opening $filename in append mode.
// Create log entry
$entry = date('Y-m-d H:i:s').' '.$_SERVER['REMOTE_ADDR'].' '.$protocol.' '.$type.' '.$idp.' '.$sp."\n";
// We are opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($WAYFLogFile, 'a')) {
return;
return;
}
// Create log entry
$entry = date('Y-m-d H:i:s').' '.$_SERVER['REMOTE_ADDR'].' '.$protocol.' '.$type.' '.$idp.' '.$sp."\n";
// Try getting lock
while (!flock($handle, LOCK_EX)){
usleep(rand(10, 100));
}
// Write $somecontent to our opened file.
if (fwrite($handle, $entry) === FALSE) {
return;
}
fwrite($handle, $entry);
// Release the lock
flock($handle, LOCK_UN);
// Close file handle
fclose($handle);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment