diff --git a/libs/keyLib.php b/libs/keyLib.php index 86ce0c9..a321677 100755 --- a/libs/keyLib.php +++ b/libs/keyLib.php @@ -87,6 +87,7 @@ return null; $data = fread($handle, filesize($fileName)); $lines = explode("\n", $data); + fclose($handle); $keyData = array(); for ($i = 1; $i < count($lines); $i++) { @@ -118,7 +119,11 @@ for ($i = 0; $i < $count; $i++) $data = $data . $i . ";" . $keyData[$i][0] . ";" . $keyData[$i][1] . "\n"; $data = $data . $count . ";" . $keyData[$count][0] . ";" . $keyData[$count][1]; + + //use exclusive lock for writing + flock($handle, LOCK_EX); $res = fwrite($handle, $data); + flock($handle, LOCK_UN); // debug Code //if ($res == false) // echo ""; diff --git a/libs/loggingLib.php b/libs/loggingLib.php index cfd3957..da5f4af 100755 --- a/libs/loggingLib.php +++ b/libs/loggingLib.php @@ -9,8 +9,8 @@ // and tutors. //============================================================================ - define ("STUDENTLOGFILE", "logs/ESE2013_studentLog.txt"); - define ("TUTORLOGFILE", "logs/ESE2013_tutorLog.txt"); + define ("STUDENTLOGFILE", "logs/ESE_studentLog.txt"); + define ("TUTORLOGFILE", "logs/ESE_tutorLog.txt"); /** * Reads all question data out of a provided log file array that has been split by new lines. @@ -178,6 +178,7 @@ // otherwise read the file and split the string at each new line $fileData = fread($handle, $length); $lines = explode("\n", $fileData); + fclose($handle); // begin parsing of the file, the beginning is the second line, because the // first should contains the disclaimer $index = 1; @@ -231,7 +232,10 @@ // each comment is escapd by a new line containing three tilde characters $fileData = $fileData . "\n" . $comment . "\n~~~"; // write the generated data to the file and close it + // use exclusive lock + flock($handle, LOCK_EX); fwrite($handle, $fileData); + flock($handle, LOCK_UN); fclose($handle); return true; } @@ -301,4 +305,4 @@ if (array_key_exists("comment", $formData) && trim($formData["comment"]) != "") array_push($commentData, $formData["comment"]); } -?> \ No newline at end of file +?>