1. <?php
  2. /**
  3. * Searches configuration files for scheduled runs, limiting memory usage.
  4. *
  5. * @param array $config_files An array of configuration file paths.
  6. * @param string $search_term The term to search for (e.g., "scheduled", "cron").
  7. * @return array An array of associative arrays, each containing the file path and the matching content.
  8. */
  9. function findScheduledRunsInConfigFiles(array $config_files, string $search_term): array
  10. {
  11. $results = [];
  12. $memory_limit = ini_get('memory_limit', '128M'); // Default memory limit
  13. foreach ($config_files as $file) {
  14. if (!file_exists($file)) {
  15. continue; // Skip if file doesn't exist
  16. }
  17. $content = file_get_contents($file);
  18. if ($content === false) {
  19. continue; // Skip if file couldn't be read
  20. }
  21. $lines = explode("\n", $content);
  22. $found = false;
  23. foreach ($lines as $line) {
  24. if (mb_stripos($line, $search_term, MB_STRIPIгноrCase) !== false) {
  25. $results[] = ['file' => $file, 'content' => $line];
  26. $found = true;
  27. }
  28. }
  29. }
  30. return $results;
  31. }
  32. // Example Usage (replace with your config file paths and search term)
  33. /*
  34. $config_files = ['config.ini', 'settings.json', 'application.yml'];
  35. $search_term = 'scheduled';
  36. $scheduled_runs = findScheduledRunsInConfigFiles($config_files, $search_term);
  37. if ($scheduled_runs) {
  38. echo "Scheduled runs found:\n";
  39. foreach ($scheduled_runs as $run) {
  40. echo "File: " . $run['file'] . "\n";
  41. echo "Content: " . $run['content'] . "\n";
  42. echo "\n";
  43. }
  44. } else {
  45. echo "No scheduled runs found.\n";
  46. }
  47. */
  48. ?>

Add your comment