Created
November 13, 2024 14:05
-
-
Save ephrin/b07c2e953a2edf3ca0fb2c488520834b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function testEndpoint($url, $iterations = 100) | |
{ | |
$times = []; | |
for ($i = 0; $i < $iterations; $i++) { | |
$start = microtime(true); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
$response = curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
$end = microtime(true); | |
$executionTime = ($end - $start) * 1000; // Convert to milliseconds | |
if ($httpCode == 200) { | |
$times[] = $executionTime; | |
} else { | |
echo "Request failed for $url with HTTP code: $httpCode\n"; | |
} | |
// Add a small delay between requests | |
usleep(100000); // 100ms delay | |
} | |
return [ | |
'min' => min($times), | |
'max' => max($times), | |
'avg' => array_sum($times) / count($times), | |
'samples' => count($times) | |
]; | |
} | |
$apps = [ | |
'app1' => [ | |
'url' => 'https://www.kautionskasse.de/form-api/healthcheck', | |
'description' => 'production PHP 7.4 [opcache.enabled=1]' | |
], | |
'app2' => [ | |
'url' => 'https://staging4.kautionskasse.de/form-api/healthcheck', | |
'description' => 'staging PHP 8.2 [opcache.enabled=0]' | |
] | |
]; | |
foreach ($apps as $key => $app) { | |
echo "Testing {$app['description']}...\n"; | |
$results = testEndpoint($app['url']); | |
$apps[$key]['results'] = $results; | |
} | |
// Print results | |
echo "\nResults:\n"; | |
echo str_repeat("-", 50) . "\n"; | |
echo sprintf("%-40s %-10s %-10s %-10s %-10s\n", "App", "Min (ms)", "Max (ms)", "Avg (ms)", "Samples"); | |
echo str_repeat("-", 50) . "\n"; | |
foreach ($apps as $key => $app) { | |
echo sprintf("%-40s %-10.2f %-10.2f %-10.2f %-10d\n", | |
$app['description'], | |
$app['results']['min'], | |
$app['results']['max'], | |
$app['results']['avg'], | |
$app['results']['samples'] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment