<?php
/**
* Searches configuration files for scheduled runs, limiting memory usage.
*
* @param array $config_files An array of configuration file paths.
* @param string $search_term The term to search for (e.g., "scheduled", "cron").
* @return array An array of associative arrays, each containing the file path and the matching content.
*/
function findScheduledRunsInConfigFiles(array $config_files, string $search_term): array
{
$results = [];
$memory_limit = ini_get('memory_limit', '128M'); // Default memory limit
foreach ($config_files as $file) {
if (!file_exists($file)) {
continue; // Skip if file doesn't exist
}
$content = file_get_contents($file);
if ($content === false) {
continue; // Skip if file couldn't be read
}
$lines = explode("\n", $content);
$found = false;
foreach ($lines as $line) {
if (mb_stripos($line, $search_term, MB_STRIPIгноrCase) !== false) {
$results[] = ['file' => $file, 'content' => $line];
$found = true;
}
}
}
return $results;
}
// Example Usage (replace with your config file paths and search term)
/*
$config_files = ['config.ini', 'settings.json', 'application.yml'];
$search_term = 'scheduled';
$scheduled_runs = findScheduledRunsInConfigFiles($config_files, $search_term);
if ($scheduled_runs) {
echo "Scheduled runs found:\n";
foreach ($scheduled_runs as $run) {
echo "File: " . $run['file'] . "\n";
echo "Content: " . $run['content'] . "\n";
echo "\n";
}
} else {
echo "No scheduled runs found.\n";
}
*/
?>
Add your comment