ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestProcessLockerFile.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_TEST_START_LOCK_CHECK = 'testStartLockCheck';
15  const PROCESS_NAME_RANDOM_PASS_BUILD = 'randomPassBuild';
16 
20  protected $lockFileStorage;
21 
25  protected $lockFileHandles;
26 
31  {
32  $this->lockFileStorage = $lockFileStorage;
33  $this->lockFileHandles = array();
34  }
35 
37  {
38  $this->requestLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
39  }
40 
42  {
43  $this->releaseLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
44  }
45 
46  public function requestRandomPassBuildLock()
47  {
48  $this->requestLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
49  }
50 
51  public function releaseRandomPassBuildLock()
52  {
53  $this->releaseLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
54  }
55 
56  private function requestLock($processName)
57  {
58  $lockFilePath = $this->getLockFilePath($processName);
59  $this->lockFileHandles[$processName] = fopen($lockFilePath, 'w');
60  flock($this->lockFileHandles[$processName], LOCK_EX);
61  }
62 
63  private function getLockFilePath($processName)
64  {
65  $path = $this->lockFileStorage->getPath();
66  return $path.'/'.$processName.'.lock';
67  }
68 
69  private function releaseLock($processName)
70  {
71  flock($this->lockFileHandles[$processName], LOCK_UN);
72  fclose($this->lockFileHandles[$processName]);
73  }
74 }