1. <?php
  2. /**
  3. * Archives configuration values for testing rate limiting.
  4. *
  5. * @param array $config An array of configuration values to archive.
  6. * @param string $archivePath The path to the directory where the archive will be stored.
  7. * @return bool True on success, false on failure.
  8. */
  9. function archiveConfigValues(array $config, string $archivePath): bool
  10. {
  11. // Ensure the archive directory exists
  12. if (!is_dir($archivePath)) {
  13. if (!mkdir($archivePath, 0777, true)) {
  14. error_log("Failed to create archive directory: " . $archivePath);
  15. return false;
  16. }
  17. }
  18. // Generate a unique filename for the archive
  19. $timestamp = time();
  20. $archiveFilename = 'config_archive_' . $timestamp . '.php';
  21. $archivePath .= '/' . $archiveFilename;
  22. // Encode the configuration values as PHP code
  23. $configString = '<?php return ' . var_export($config, true) . ';';
  24. // Write the encoded configuration to the archive file
  25. if (file_put_contents($archivePath, $configString) === false) {
  26. error_log("Failed to write archive file: " . $archivePath);
  27. return false;
  28. }
  29. return true;
  30. }

Add your comment