From d7c17ceef9fc3870fb45f1baa5bb6a7da724d579 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 29 Apr 2025 15:47:29 -0400 Subject: [PATCH] feat: added app to fill a pvc in 1GB increments --- examples/lamp/php/index.php | 89 ++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/examples/lamp/php/index.php b/examples/lamp/php/index.php index 6cf1a50..09f165d 100644 --- a/examples/lamp/php/index.php +++ b/examples/lamp/php/index.php @@ -1,3 +1,90 @@ PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, +]; + +try { + $pdo = new PDO($dsn, $user, $pass, $options); + $pdo->exec("CREATE DATABASE IF NOT EXISTS `$db`"); + $pdo->exec("USE `$db`"); + $pdo->exec(" + CREATE TABLE IF NOT EXISTS filler ( + id INT AUTO_INCREMENT PRIMARY KEY, + data LONGBLOB + ) + "); +} catch (\PDOException $e) { + die("Database setup failed: " . $e->getMessage()); +} + +// Disk usage (PVC mount path) +$mountPath = '/var/lib/mysql'; // Change this if PVC is mounted elsewhere +$freeBytes = disk_free_space($mountPath); +$totalBytes = disk_total_space($mountPath); +$freeGB = round($freeBytes / (1024 ** 3), 2); +$totalGB = round($totalBytes / (1024 ** 3), 2); +$usedGB = round(($totalBytes - $freeBytes) / (1024 ** 3), 2); + +$message = ''; + + + +if ($_SERVER['REQUEST_METHOD'] === 'POST'&& isset($_POST['fill'])) { + + + + $chunkSize = 1024 * 1024; // 1MB + $iterations = 1024; // 1GB total + $data = str_repeat(random_bytes(1024), 1024); // ~1MB binary blob + + $stmt = $pdo->prepare("INSERT INTO filler (data) VALUES (:data)"); + + for ($i = 0; $i < $iterations; $i++) { + $stmt->execute([':data' => $data]); + } + + + clearstatcache(); + $freeBytes = disk_free_space($mountPath); + $freeGB = round($freeBytes / (1024 ** 3), 2); + $usedGB = round(($totalBytes - $freeBytes) / (1024 ** 3), 2); + + $message = "

✅ 1GB inserted. Disk usage updated.

"; +} ?> + + + + + Volume Filler + + +

Kubernetes PVC Filler

+ + + +
+ +
+ + + +