Skip to content

Instantly share code, notes, and snippets.

@pavel-rossinsky
Last active November 14, 2024 17:21
Show Gist options
  • Save pavel-rossinsky/3728131b572cd247642b3ed9cadfe625 to your computer and use it in GitHub Desktop.
Save pavel-rossinsky/3728131b572cd247642b3ed9cadfe625 to your computer and use it in GitHub Desktop.
PHP script to list and purge all queues in a local ElasticMQ instance running on Docker. It uses Symfony's HttpClient to interact with the service, sending ListQueues and PurgeQueue requests, and outputs the results to the console.
<?php
use Symfony\Component\HttpClient\HttpClient;
require __DIR__ . '/vendor/autoload.php';
$client = HttpClient::create();
$endpoint = 'http://localhost:9424';
try {
$response = $client->request('POST', "$endpoint", [
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'body' => [
'Action' => 'ListQueues',
]
]);
$rawContent = $response->getContent();
echo "Raw Response: $rawContent\n"; // For debugging
$xml = new SimpleXMLElement($rawContent);
$queueUrls = $xml->ListQueuesResult->QueueUrl ?? [];
if (empty($queueUrls)) {
echo "No queues found.\n";
exit;
}
foreach ($queueUrls as $queueUrl) {
$client->request('POST', $queueUrl, [
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'body' => [
'Action' => 'PurgeQueue',
]
]);
echo "Purged queue: $queueUrl\n";
}
} catch (Throwable $e) {
echo "Error: " . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment