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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

BaseMemcacheProfilerStorage.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 7.96 KiB


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\HttpKernel\Profiler;
013   
014  @trigger_error('The '.__NAMESPACE__.'\BaseMemcacheProfilerStorage class is deprecated since Symfony 2.8 and will be removed in 3.0. Use FileProfilerStorage instead.', E_USER_DEPRECATED);
015   
016  /**
017   * Base Memcache storage for profiling information in a Memcache.
018   *
019   * @author Andrej Hudec <pulzarraider@gmail.com>
020   *
021   * @deprecated Deprecated since Symfony 2.8, to be removed in Symfony 3.0.
022   *             Use {@link FileProfilerStorage} instead.
023   */
024  abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface
025  {
026      const TOKEN_PREFIX = 'sf_profiler_';
027   
028      protected $dsn;
029      protected $lifetime;
030   
031      /**
032       * Constructor.
033       *
034       * @param string $dsn      A data source name
035       * @param string $username
036       * @param string $password
037       * @param int    $lifetime The lifetime to use for the purge
038       */
039      public function __construct($dsn, $username = '', $password = '', $lifetime = 86400)
040      {
041          $this->dsn = $dsn;
042          $this->lifetime = (int) $lifetime;
043      }
044   
045      /**
046       * {@inheritdoc}
047       */
048      public function find($ip, $url, $limit, $method, $start = null, $end = null)
049      {
050          $indexName = $this->getIndexName();
051   
052          $indexContent = $this->getValue($indexName);
053          if (!$indexContent) {
054              return array();
055          }
056   
057          $profileList = explode("\n", $indexContent);
058          $result = array();
059   
060          foreach ($profileList as $item) {
061              if ($limit === 0) {
062                  break;
063              }
064   
065              if ($item == '') {
066                  continue;
067              }
068   
069              $values = explode("\t", $item, 7);
070              list($itemToken, $itemIp, $itemMethod, $itemUrl, $itemTime, $itemParent) = $values;
071              $statusCode = isset($values[6]) ? $values[6] : null;
072   
073              $itemTime = (int) $itemTime;
074   
075              if ($ip && false === strpos($itemIp, $ip) || $url && false === strpos($itemUrl, $url) || $method && false === strpos($itemMethod, $method)) {
076                  continue;
077              }
078   
079              if (!empty($start) && $itemTime < $start) {
080                  continue;
081              }
082   
083              if (!empty($end) && $itemTime > $end) {
084                  continue;
085              }
086   
087              $result[$itemToken] = array(
088                  'token' => $itemToken,
089                  'ip' => $itemIp,
090                  'method' => $itemMethod,
091                  'url' => $itemUrl,
092                  'time' => $itemTime,
093                  'parent' => $itemParent,
094                  'status_code' => $statusCode,
095              );
096              --$limit;
097          }
098   
099          usort($result, function ($a, $b) {
100              if ($a['time'] === $b['time']) {
101                  return 0;
102              }
103   
104              return $a['time'] > $b['time'] ? -1 : 1;
105          });
106   
107          return $result;
108      }
109   
110      /**
111       * {@inheritdoc}
112       */
113      public function purge()
114      {
115          // delete only items from index
116          $indexName = $this->getIndexName();
117   
118          $indexContent = $this->getValue($indexName);
119   
120          if (!$indexContent) {
121              return false;
122          }
123   
124          $profileList = explode("\n", $indexContent);
125   
126          foreach ($profileList as $item) {
127              if ($item == '') {
128                  continue;
129              }
130   
131              if (false !== $pos = strpos($item, "\t")) {
132                  $this->delete($this->getItemName(substr($item, 0, $pos)));
133              }
134          }
135   
136          return $this->delete($indexName);
137      }
138   
139      /**
140       * {@inheritdoc}
141       */
142      public function read($token)
143      {
144          if (empty($token)) {
145              return false;
146          }
147   
148          $profile = $this->getValue($this->getItemName($token));
149   
150          if (false !== $profile) {
151              $profile = $this->createProfileFromData($token, $profile);
152          }
153   
154          return $profile;
155      }
156   
157      /**
158       * {@inheritdoc}
159       */
160      public function write(Profile $profile)
161      {
162          $data = array(
163              'token' => $profile->getToken(),
164              'parent' => $profile->getParentToken(),
165              'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
166              'data' => $profile->getCollectors(),
167              'ip' => $profile->getIp(),
168              'method' => $profile->getMethod(),
169              'url' => $profile->getUrl(),
170              'time' => $profile->getTime(),
171          );
172   
173          $profileIndexed = false !== $this->getValue($this->getItemName($profile->getToken()));
174   
175          if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime)) {
176              if (!$profileIndexed) {
177                  // Add to index
178                  $indexName = $this->getIndexName();
179   
180                  $indexRow = implode("\t", array(
181                      $profile->getToken(),
182                      $profile->getIp(),
183                      $profile->getMethod(),
184                      $profile->getUrl(),
185                      $profile->getTime(),
186                      $profile->getParentToken(),
187                      $profile->getStatusCode(),
188                  ))."\n";
189   
190                  return $this->appendValue($indexName, $indexRow, $this->lifetime);
191              }
192   
193              return true;
194          }
195   
196          return false;
197      }
198   
199      /**
200       * Retrieve item from the memcache server.
201       *
202       * @param string $key
203       *
204       * @return mixed
205       */
206      abstract protected function getValue($key);
207   
208      /**
209       * Store an item on the memcache server under the specified key.
210       *
211       * @param string $key
212       * @param mixed  $value
213       * @param int    $expiration
214       *
215       * @return bool
216       */
217      abstract protected function setValue($key, $value, $expiration = 0);
218   
219      /**
220       * Delete item from the memcache server.
221       *
222       * @param string $key
223       *
224       * @return bool
225       */
226      abstract protected function delete($key);
227   
228      /**
229       * Append data to an existing item on the memcache server.
230       *
231       * @param string $key
232       * @param string $value
233       * @param int    $expiration
234       *
235       * @return bool
236       */
237      abstract protected function appendValue($key, $value, $expiration = 0);
238   
239      private function createProfileFromData($token, $data, $parent = null)
240      {
241          $profile = new Profile($token);
242          $profile->setIp($data['ip']);
243          $profile->setMethod($data['method']);
244          $profile->setUrl($data['url']);
245          $profile->setTime($data['time']);
246          $profile->setCollectors($data['data']);
247   
248          if (!$parent && $data['parent']) {
249              $parent = $this->read($data['parent']);
250          }
251   
252          if ($parent) {
253              $profile->setParent($parent);
254          }
255   
256          foreach ($data['children'] as $token) {
257              if (!$token) {
258                  continue;
259              }
260   
261              if (!$childProfileData = $this->getValue($this->getItemName($token))) {
262                  continue;
263              }
264   
265              $profile->addChild($this->createProfileFromData($token, $childProfileData, $profile));
266          }
267   
268          return $profile;
269      }
270   
271      /**
272       * Get item name.
273       *
274       * @param string $token
275       *
276       * @return string
277       */
278      private function getItemName($token)
279      {
280          $name = self::TOKEN_PREFIX.$token;
281   
282          if ($this->isItemNameValid($name)) {
283              return $name;
284          }
285   
286          return false;
287      }
288   
289      /**
290       * Get name of index.
291       *
292       * @return string
293       */
294      private function getIndexName()
295      {
296          $name = self::TOKEN_PREFIX.'index';
297   
298          if ($this->isItemNameValid($name)) {
299              return $name;
300          }
301   
302          return false;
303      }
304   
305      private function isItemNameValid($name)
306      {
307          $length = strlen($name);
308   
309          if ($length > 250) {
310              throw new \RuntimeException(sprintf('The memcache item key "%s" is too long (%s bytes). Allowed maximum size is 250 bytes.', $name, $length));
311          }
312   
313          return true;
314      }
315  }
316