<?php
/**
* Archives configuration values for testing rate limiting.
*
* @param array $config An array of configuration values to archive.
* @param string $archivePath The path to the directory where the archive will be stored.
* @return bool True on success, false on failure.
*/
function archiveConfigValues(array $config, string $archivePath): bool
{
// Ensure the archive directory exists
if (!is_dir($archivePath)) {
if (!mkdir($archivePath, 0777, true)) {
error_log("Failed to create archive directory: " . $archivePath);
return false;
}
}
// Generate a unique filename for the archive
$timestamp = time();
$archiveFilename = 'config_archive_' . $timestamp . '.php';
$archivePath .= '/' . $archiveFilename;
// Encode the configuration values as PHP code
$configString = '<?php return ' . var_export($config, true) . ';';
// Write the encoded configuration to the archive file
if (file_put_contents($archivePath, $configString) === false) {
error_log("Failed to write archive file: " . $archivePath);
return false;
}
return true;
}
Add your comment