コード例 #1
0
 /**
  * Page through the results while validating no memory leaks exists
  *
  * @param $start Starting memory value
  * @return int Number of rows visited
  */
 private function validatePageResults($rows)
 {
     // Get the starting memory usage
     $start = memory_get_usage() / 1024;
     if (Integration::isDebug() && Integration::isVerbose()) {
         fprintf(STDOUT, "Start Usage: %dkb" . PHP_EOL, $start);
     }
     // Page over each result set and count the number of rows visited
     $count = $rows->count();
     while ($rows = $rows->nextPage()) {
         if ($rows->count() != 0) {
             $count += $rows->count();
             if (Integration::isDebug() && Integration::isVerbose()) {
                 fprintf(STDOUT, "Page %d: Current memory usage is %dkb" . PHP_EOL, $count / 2, memory_get_usage() / 1024 - $start);
             }
         }
     }
     // Get the final memory usage (and apply a tolerance to compensate for GC)
     $end = memory_get_usage() / 1024;
     if (Integration::isDebug() && Integration::isVerbose()) {
         fprintf(STDOUT, "End Usage: %dkb [%dkb]" . PHP_EOL, $end, $end - $start);
     }
     $difference = $end - $start - 20;
     // 20KB tolerance
     $this->assertLessThanOrEqual(0, $difference);
     // Return the number of rows visited
     return $count;
 }