// reset process monitor timers in each loop pmr('some api call to import ' . $fileInfo['name']); // 1. step some api call runApiCallToGetXMLFile($fileInfo, $memoryLeakData); // pms is shortcut for ProcessMonitor::addSummary() // when processing can be split in several steps as in this case // it is very useful to track time and memory usage for each step separately // track api call time + download response time pms("get file {$fileInfo['name']} xml: " . ProcessMonitor::formatSize($fileInfo['size'] * 1000, ProcessMonitor::SIZE_AUTO) . " <a href='/examples/processMonitor.php?file={$fileInfo['name']}'>Run again >> </a>" . " <br/> see imported xml: <a href='/some_url/{$fileInfo['name']}' target='_blank'>" . $fileInfo['name'] . "</a>", null, 'time_api_call'); // 2. step - parsing xml response parseXMLFile($fileInfo, $memoryLeakData); // track time to validate and parse xml pms('parsed ' . $fileInfo['name'], $fileInfo, 'time_parse'); // 3. step - preparing and storing data to db, etc storeData($fileInfo, $memoryLeakData); // track time to process and store the data pms('processed ' . $fileInfo['name'], $fileInfo, 'time_processed'); // intentionally condition for always true in this example if ($error = true) { // pme is shortcut to output error messages // you may include whatever data useful for debugging // for more variables to dump use array pme("Error description", ['some useful data']); } $count++; } pmr("XML files processed: {$count}"); pmr('Total run time: ' . ProcessMonitor::formatTime(ProcessMonitor::getTotalTime())); // this code should be called on application shutdown event in nette: // $this->application->onShutdown[] = addJsAfterTheScriptIsDone(); addJsAfterTheScriptIsDone();