Zum Inhalt springen

Logging In Loop (ARCH7164)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key php.logging.logging-in-loop · Severity info · Category logging

Logging on every iteration inside a loop body can flood the log sink and degrade performance.

<?php
foreach ($orders as $order) {
$this->logger->info('Processing order', ['id' => $order->getId()]);
$this->process($order);
}
<?php
foreach ($orders as $order) {
$this->process($order);
}
$this->logger->info('Processed orders', ['count' => count($orders)]);

Write a summary record outside the loop instead of logging on every iteration.