Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
flock.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\lock;
015
016 /**
017 * File locking class
018 */
019 class flock
020 {
021 /**
022 * Path to the file to which access is controlled
023 *
024 * @var string
025 */
026 private $path;
027
028 /**
029 * File pointer for the lock file
030 * @var string
031 */
032 private $lock_fp;
033
034 /**
035 * Constructor.
036 *
037 * You have to call acquire() to actually acquire the lock.
038 *
039 * @param string $path Path to the file to which access is controlled
040 */
041 public function __construct($path)
042 {
043 $this->path = $path;
044 $this->lock_fp = null;
045 }
046
047 /**
048 * Tries to acquire the lock.
049 *
050 * If the lock is already held by another process, this call will block
051 * until the other process releases the lock. If a lock is acquired and
052 * is not released before script finishes but the process continues to
053 * live (apache/fastcgi) then subsequent processes trying to acquire
054 * the same lock will be blocked forever.
055 *
056 * If the lock is already held by the same process via another instance
057 * of this class, this call will block forever.
058 *
059 * If flock function is disabled in php or fails to work, lock
060 * acquisition will fail and false will be returned.
061 *
062 * @return bool true if lock was acquired
063 * false otherwise
064 */
065 public function acquire()
066 {
067 if ($this->lock_fp)
068 {
069 return false;
070 }
071
072 // For systems that can't have two processes opening
073 // one file for writing simultaneously
074 if (file_exists($this->path . '.lock'))
075 {
076 $mode = 'rb';
077 }
078 else
079 {
080 $mode = 'wb';
081 }
082
083 $this->lock_fp = @fopen($this->path . '.lock', $mode);
084
085 if ($mode == 'wb')
086 {
087 if (!$this->lock_fp)
088 {
089 // Two processes may attempt to create lock file at the same time.
090 // Have the losing process try opening the lock file again for reading
091 // on the assumption that the winning process created it
092 $mode = 'rb';
093 $this->lock_fp = @fopen($this->path . '.lock', $mode);
094 }
095 else
096 {
097 // Only need to set mode when the lock file is written
098 @chmod($this->path . '.lock', 0666);
099 }
100 }
101
102 if ($this->lock_fp)
103 {
104 @flock($this->lock_fp, LOCK_EX);
105 }
106
107 return (bool) $this->lock_fp;
108 }
109
110 /**
111 * Does this process own the lock?
112 *
113 * @return bool true if lock is owned
114 * false otherwise
115 */
116 public function owns_lock()
117 {
118 return (bool) $this->lock_fp;
119 }
120
121 /**
122 * Releases the lock.
123 *
124 * The lock must have been previously obtained, that is, acquire() call
125 * was issued and returned true.
126 *
127 * Note: Attempting to release a lock that is already released,
128 * that is, calling release() multiple times, is harmless.
129 *
130 * @return null
131 */
132 public function release()
133 {
134 if ($this->lock_fp)
135 {
136 @flock($this->lock_fp, LOCK_UN);
137 fclose($this->lock_fp);
138 $this->lock_fp = null;
139 }
140 }
141 }
142