<?php
/**
* Instruments query strings for internal tooling with error logging.
*
* @param string $callback The function to be called for each query string.
* @param array $query_strings An array of query strings to process.
* @return array An array of results from the callback function.
*/
function instrumentQueryStrings(callable $callback, array $query_strings): array
{
$results = [];
foreach ($query_strings as $query_string) {
try {
// Log the query string.
error_log("Processing query string: " . $query_string);
// Call the callback function with the query string.
$result = $callback($query_string);
$results[] = $result;
} catch (Exception $e) {
// Log the error.
error_log("Error processing query string: " . $query_string . ". Error: " . $e->getMessage());
$results[] = ['error' => $e->getMessage()]; // Store error in results
}
}
return $results;
}
// Example usage (for testing)
if (isset($_GET)) {
$query_strings = $_GET;
$callback = function ($query_string) {
// Simulate some processing.
return "Processed: " . $query_string;
};
$results = instrumentQueryStrings($callback, $query_strings);
//Output the results (for testing)
print_r($results);
}
?>
Add your comment