Skip to content

Commit

Permalink
Uses curl to fetch k6 binary to solve github redirect issues
Browse files Browse the repository at this point in the history
Makes use of `CURLOPT_FOLLOWLOCATION` to allow a redirect on github.
  • Loading branch information
RobinWieske authored and Robin Wieske committed Dec 13, 2024
1 parent 9ec437a commit 95d248e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/K6.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,20 @@ public static function download(): void
$url = sprintf(self::K6_URL, self::K6_VERSION, self::K6_VERSION, $os, $arch, $extension);
$fileName = basename($url);

if (false === ($binary = file_get_contents($url))) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$binary = curl_exec($ch);

if (false === $binary || 200 !== curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
curl_close($ch);
throw new RuntimeException('Unable to download k6 binary.');
}

curl_close($ch);

if (file_put_contents(self::BIN_DIR.$fileName, $binary) === false) {
throw new RuntimeException('Unable to save k6 binary.');
}
Expand Down

0 comments on commit 95d248e

Please sign in to comment.