Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
WindowsPipes.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Process\Pipes;
013
014 use Symfony\Component\Process\Exception\RuntimeException;
015 use Symfony\Component\Process\Process;
016
017 /**
018 * WindowsPipes implementation uses temporary files as handles.
019 *
020 * @see https://bugs.php.net/51800
021 * @see https://bugs.php.net/65650
022 *
023 * @author Romain Neutron <imprec@gmail.com>
024 *
025 * @internal
026 */
027 class WindowsPipes extends AbstractPipes
028 {
029 private $files = [];
030 private $fileHandles = [];
031 private $lockHandles = [];
032 private $readBytes = [
033 Process::STDOUT => 0,
034 Process::STDERR => 0,
035 ];
036 private $haveReadSupport;
037
038 public function __construct($input, $haveReadSupport)
039 {
040 $this->haveReadSupport = (bool) $haveReadSupport;
041
042 if ($this->haveReadSupport) {
043 // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
044 // Workaround for this problem is to use temporary files instead of pipes on Windows platform.
045 //
046 // @see https://bugs.php.net/51800
047 $pipes = [
048 Process::STDOUT => Process::OUT,
049 Process::STDERR => Process::ERR,
050 ];
051 $tmpDir = sys_get_temp_dir();
052 $lastError = 'unknown reason';
053 set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; });
054 for ($i = 0;; ++$i) {
055 foreach ($pipes as $pipe => $name) {
056 $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
057
058 if (!$h = fopen($file.'.lock', 'w')) {
059 if (file_exists($file.'.lock')) {
060 continue 2;
061 }
062 restore_error_handler();
063 throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError);
064 }
065 if (!flock($h, \LOCK_EX | \LOCK_NB)) {
066 continue 2;
067 }
068 if (isset($this->lockHandles[$pipe])) {
069 flock($this->lockHandles[$pipe], \LOCK_UN);
070 fclose($this->lockHandles[$pipe]);
071 }
072 $this->lockHandles[$pipe] = $h;
073
074 if (!fclose(fopen($file, 'w')) || !$h = fopen($file, 'r')) {
075 flock($this->lockHandles[$pipe], \LOCK_UN);
076 fclose($this->lockHandles[$pipe]);
077 unset($this->lockHandles[$pipe]);
078 continue 2;
079 }
080 $this->fileHandles[$pipe] = $h;
081 $this->files[$pipe] = $file;
082 }
083 break;
084 }
085 restore_error_handler();
086 }
087
088 parent::__construct($input);
089 }
090
091 public function __destruct()
092 {
093 $this->close();
094 }
095
096 /**
097 * {@inheritdoc}
098 */
099 public function getDescriptors()
100 {
101 if (!$this->haveReadSupport) {
102 $nullstream = fopen('NUL', 'c');
103
104 return [
105 ['pipe', 'r'],
106 $nullstream,
107 $nullstream,
108 ];
109 }
110
111 // We're not using pipe on Windows platform as it hangs (https://bugs.php.net/51800)
112 // We're not using file handles as it can produce corrupted output https://bugs.php.net/65650
113 // So we redirect output within the commandline and pass the nul device to the process
114 return [
115 ['pipe', 'r'],
116 ['file', 'NUL', 'w'],
117 ['file', 'NUL', 'w'],
118 ];
119 }
120
121 /**
122 * {@inheritdoc}
123 */
124 public function getFiles()
125 {
126 return $this->files;
127 }
128
129 /**
130 * {@inheritdoc}
131 */
132 public function readAndWrite($blocking, $close = false)
133 {
134 $this->unblock();
135 $w = $this->write();
136 $read = $r = $e = [];
137
138 if ($blocking) {
139 if ($w) {
140 @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6);
141 } elseif ($this->fileHandles) {
142 usleep(Process::TIMEOUT_PRECISION * 1E6);
143 }
144 }
145 foreach ($this->fileHandles as $type => $fileHandle) {
146 $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]);
147
148 if (isset($data[0])) {
149 $this->readBytes[$type] += \strlen($data);
150 $read[$type] = $data;
151 }
152 if ($close) {
153 ftruncate($fileHandle, 0);
154 fclose($fileHandle);
155 flock($this->lockHandles[$type], \LOCK_UN);
156 fclose($this->lockHandles[$type]);
157 unset($this->fileHandles[$type], $this->lockHandles[$type]);
158 }
159 }
160
161 return $read;
162 }
163
164 /**
165 * {@inheritdoc}
166 */
167 public function haveReadSupport()
168 {
169 return $this->haveReadSupport;
170 }
171
172 /**
173 * {@inheritdoc}
174 */
175 public function areOpen()
176 {
177 return $this->pipes && $this->fileHandles;
178 }
179
180 /**
181 * {@inheritdoc}
182 */
183 public function close()
184 {
185 parent::close();
186 foreach ($this->fileHandles as $type => $handle) {
187 ftruncate($handle, 0);
188 fclose($handle);
189 flock($this->lockHandles[$type], \LOCK_UN);
190 fclose($this->lockHandles[$type]);
191 }
192 $this->fileHandles = $this->lockHandles = [];
193 }
194 }
195