You are here

public function BaseMemcacheProfilerStorage::find in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Profiler/BaseMemcacheProfilerStorage.php \Symfony\Component\HttpKernel\Profiler\BaseMemcacheProfilerStorage::find()

Finds profiler tokens for the given criteria.

Parameters

string $ip The IP:

string $url The URL:

string $limit The maximum number of tokens to return:

string $method The request method:

int|null $start The start date to search from:

int|null $end The end date to search to:

Return value

array An array of tokens

Overrides ProfilerStorageInterface::find

File

vendor/symfony/http-kernel/Profiler/BaseMemcacheProfilerStorage.php, line 43

Class

BaseMemcacheProfilerStorage
Base Memcache storage for profiling information in a Memcache.

Namespace

Symfony\Component\HttpKernel\Profiler

Code

public function find($ip, $url, $limit, $method, $start = null, $end = null) {
  $indexName = $this
    ->getIndexName();
  $indexContent = $this
    ->getValue($indexName);
  if (!$indexContent) {
    return array();
  }
  $profileList = explode("\n", $indexContent);
  $result = array();
  foreach ($profileList as $item) {
    if ($limit === 0) {
      break;
    }
    if ($item == '') {
      continue;
    }
    $values = explode("\t", $item, 7);
    list($itemToken, $itemIp, $itemMethod, $itemUrl, $itemTime, $itemParent) = $values;
    $statusCode = isset($values[6]) ? $values[6] : null;
    $itemTime = (int) $itemTime;
    if ($ip && false === strpos($itemIp, $ip) || $url && false === strpos($itemUrl, $url) || $method && false === strpos($itemMethod, $method)) {
      continue;
    }
    if (!empty($start) && $itemTime < $start) {
      continue;
    }
    if (!empty($end) && $itemTime > $end) {
      continue;
    }
    $result[$itemToken] = array(
      'token' => $itemToken,
      'ip' => $itemIp,
      'method' => $itemMethod,
      'url' => $itemUrl,
      'time' => $itemTime,
      'parent' => $itemParent,
      'status_code' => $statusCode,
    );
    --$limit;
  }
  usort($result, function ($a, $b) {
    if ($a['time'] === $b['time']) {
      return 0;
    }
    return $a['time'] > $b['time'] ? -1 : 1;
  });
  return $result;
}