mirror of
https://github.com/fsr/eseeva
synced 2025-01-18 16:01:41 +01:00
adds locking
This commit is contained in:
parent
897d70ca5c
commit
f0ac644d7e
2 changed files with 12 additions and 3 deletions
|
@ -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 "<script type='text/javascript'>alert('file not written');</script>";
|
||||
|
|
|
@ -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"]);
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue