ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionProcessLockerFile.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionProcessLocker.php';
5 
13 {
14  const PROCESS_NAME_PERSIST_WORKING_STATE = 'persistWorkingState';
15 
19  protected $lockFileStorage;
20 
24  protected $lockFileHandles;
25 
30  {
31  $this->lockFileStorage = $lockFileStorage;
32  $this->lockFileHandles = array();
33  }
34 
36  {
37  $this->requestLock(self::PROCESS_NAME_PERSIST_WORKING_STATE);
38  }
39 
41  {
42  $this->releaseLock(self::PROCESS_NAME_PERSIST_WORKING_STATE);
43  }
44 
45  private function requestLock($processName)
46  {
47  $lockFilePath = $this->getLockFilePath($processName);
48  $this->lockFileHandles[$processName] = fopen($lockFilePath, 'w');
49  flock($this->lockFileHandles[$processName], LOCK_EX);
50  }
51 
52  private function getLockFilePath($processName)
53  {
54  $path = $this->lockFileStorage->getPath();
55  return $path.'/'.$processName.'.lock';
56  }
57 
58  private function releaseLock($processName)
59  {
60  flock($this->lockFileHandles[$processName], LOCK_UN);
61  fclose($this->lockFileHandles[$processName]);
62  }
63 }