diff --git a/lab.php b/lab.php index eb48a78..ca429aa 100644 --- a/lab.php +++ b/lab.php @@ -2,23 +2,189 @@ // PHP Backend API Handler voor AJAX interacties if (isset($_GET['action'])) { header('Content-Type: application/json; charset=utf-8'); +/** + * Web & PC Studio - Dev Lab & Webserver Performance Suite + * Uitgebreide diagnostics & benchmark suite voor webserver capaciteit en doorvoersnelheid. + */ + +// Helper functies voor benchmarks +function benchmarkCPU() { + $start = microtime(true); + $iterations = 80000; if ($_GET['action'] === 'benchmark') { $iterations = 75000; $start = microtime(true); $memStart = memory_get_usage(); + $val = 1.0; + for ($i = 1; $i <= $iterations; $i++) { + $val = sqrt($val + $i) * sin($i); + } + + $hash = 'webenpcstudio'; + for ($i = 0; $i < 40000; $i++) { + $hash = hash('sha256', $hash . $i); + } + + $duration = (microtime(true) - $start) * 1000; + $ops = round(($iterations + 40000) / (max(0.001, $duration) / 1000)); + + return [ + 'status' => 'success', + 'duration_ms' => round($duration, 2), + 'ops_per_sec' => number_format($ops, 0, ',', '.'), + 'raw_ops' => $ops + ]; +} // Rekenkundige en hashing benchmark $hash = 'webenpcstudio'; for ($i = 0; $i < $iterations; $i++) { $hash = hash('sha256', $hash . $i); +function benchmarkMemory() { + $start = microtime(true); + $startMem = memory_get_usage(); + + $arr = []; + for ($i = 0; $i < 50000; $i++) { + $arr['key_' . $i] = [ + 'id' => $i, + 'val' => $i * 1.5, + 'studio' => 'WebenPCStudio' + ]; + } + + ksort($arr); + $serialized = serialize($arr); + $unserialized = unserialize($serialized); + unset($arr, $serialized, $unserialized); + + $duration = (microtime(true) - $start) * 1000; + $peakMem = (memory_get_peak_usage() - $startMem) / (1024 * 1024); + $throughput = round(150000 / (max(0.001, $duration) / 1000)); + + return [ + 'status' => 'success', + 'duration_ms' => round($duration, 2), + 'peak_mem_mb' => round(max(0.1, $peakMem), 2), + 'ops_per_sec' => number_format($throughput, 0, ',', '.'), + 'raw_ops' => $throughput + ]; +} + +function benchmarkDiskIO() { + $tempDir = sys_get_temp_dir(); + $tempFile = tempnam($tempDir, 'wpc_bench_'); + if (!$tempFile) { + return ['status' => 'error', 'message' => 'Kan tijdelijk bestand niet aanmaken']; + } + + $chunkSize = 64 * 1024; // 64 KB + $chunks = 48; // ~3 MB totaal + $dummyData = str_repeat('WPCStudio2026_TEST_STRING_ABCD!', 2048); // 64 KB + + // Write test + $writeStart = microtime(true); + $fp = fopen($tempFile, 'wb'); + if (!$fp) { + @unlink($tempFile); + return ['status' => 'error', 'message' => 'Kan bestand niet openen']; + } + for ($i = 0; $i < $chunks; $i++) { + fwrite($fp, $dummyData); + } + fflush($fp); + fclose($fp); + $writeTime = max(0.0005, microtime(true) - $writeStart); + + // Read test + $readStart = microtime(true); + $fp = fopen($tempFile, 'rb'); + if ($fp) { + while (!feof($fp)) { + fread($fp, $chunkSize); } + fclose($fp); + } + $readTime = max(0.0005, microtime(true) - $readStart); + + $totalMB = ($chunks * $chunkSize) / (1024 * 1024); + $writeSpeed = round($totalMB / $writeTime, 1); + $readSpeed = round($totalMB / $readTime, 1); + + @unlink($tempFile); + + return [ + 'status' => 'success', + 'file_size_mb' => round($totalMB, 2), + 'write_speed_mb_s' => $writeSpeed, + 'read_speed_mb_s' => $readSpeed, + 'write_time_ms' => round($writeTime * 1000, 1), + 'read_time_ms' => round($readTime * 1000, 1) + ]; +} $duration = (microtime(true) - $start) * 1000; // in milliseconden $memPeak = memory_get_peak_usage() / (1024 * 1024); // MB $opsPerSec = round($iterations / ($duration / 1000)); +function benchmarkStringJSON() { + $start = microtime(true); + $data = []; + for ($i = 0; $i < 15000; $i++) { + $data[] = [ + 'id' => $i, + 'email' => "user{$i}@webenpcstudio.nl", + 'tags' => ['git', 'php', 'speed', 'server'], + 'active' => ($i % 2 === 0) + ]; + } + $json = json_encode($data); + $decoded = json_decode($json, true); + + preg_match_all('/[a-zA-Z0-9._%+-]+@webenpcstudio\.nl/', $json, $matches); + + $duration = (microtime(true) - $start) * 1000; + $throughput = round(15000 / (max(0.001, $duration) / 1000)); + + return [ + 'status' => 'success', + 'duration_ms' => round($duration, 2), + 'records_per_sec' => number_format($throughput, 0, ',', '.'), + 'json_size_kb' => round(strlen($json) / 1024, 1), + 'raw_ops' => $throughput + ]; +} echo json_encode([ +function benchmarkDatabase() { + if (!extension_loaded('pdo_sqlite')) { + return [ + 'status' => 'skipped', + 'message' => 'PDO SQLite niet beschikbaar', + 'tps' => 0, + 'duration_ms' => 0 + ]; + } + try { + $start = microtime(true); + $pdo = new PDO('sqlite::memory:'); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo->exec('CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT, val REAL)'); + + $pdo->beginTransaction(); + $stmt = $pdo->prepare('INSERT INTO test (name, val) VALUES (?, ?)'); + for ($i = 0; $i < 2500; $i++) { + $stmt->execute(['item_' . $i, mt_rand(1, 1000) / 10]); + } + $pdo->commit(); + + $stmt2 = $pdo->query('SELECT AVG(val), COUNT(*) FROM test WHERE val > 500'); + $stmt2->fetch(); + + $duration = (microtime(true) - $start) * 1000; + $tps = round(2500 / (max(0.001, $duration) / 1000)); + + return [ 'status' => 'success', 'iterations' => number_format($iterations, 0, ',', '.'), 'duration_ms' => round($duration, 2), @@ -26,29 +192,188 @@ if (isset($_GET['action'])) { 'peak_memory' => round($memPeak, 2) . ' MB', 'php_version' => PHP_VERSION, 'final_hash' => substr($hash, 0, 16) . '...' + 'tps' => number_format($tps, 0, ',', '.'), + 'records' => 2500, + 'raw_tps' => $tps + ]; + } catch (Exception $e) { + return [ + 'status' => 'error', + 'message' => $e->getMessage() + ]; + } +} + +function getOpcacheInfo() { + if (function_exists('opcache_get_status') && ($status = @opcache_get_status(false))) { + $mem = $status['memory_usage'] ?? []; + return [ + 'enabled' => true, + 'used_mb' => round(($mem['used_memory'] ?? 0) / (1024 * 1024), 1), + 'free_mb' => round(($mem['free_memory'] ?? 0) / (1024 * 1024), 1), + 'hit_rate' => round($status['opcache_statistics']['opcache_hit_rate'] ?? 0, 1) . '%', + 'jit' => !empty($status['jit']['enabled']) ? 'Actief' : 'Inactief' + ]; + } + return [ + 'enabled' => false, + 'message' => 'Niet geactiveerd' + ]; +} + +// ========================================== +// API Routing voor AJAX Verzoeken +// ========================================== +if (isset($_GET['action'])) { + header('Content-Type: application/json; charset=utf-8'); + + // 1. Snelle Ping + if ($_GET['action'] === 'ping') { + echo json_encode([ + 'status' => 'pong', + 'timestamp' => microtime(true), + 'server_time' => date('H:i:s.u') ]); exit; } if ($_GET['action'] === 'hash' && isset($_POST['text'])) { $input = (string)$_POST['text']; + // 2. Afzonderlijke Benchmark Acties + if ($_GET['action'] === 'bench_cpu') { + echo json_encode(benchmarkCPU()); + exit; + } + if ($_GET['action'] === 'bench_memory') { + echo json_encode(benchmarkMemory()); + exit; + } + if ($_GET['action'] === 'bench_disk') { + echo json_encode(benchmarkDiskIO()); + exit; + } + if ($_GET['action'] === 'bench_string') { + echo json_encode(benchmarkStringJSON()); + exit; + } + if ($_GET['action'] === 'bench_db') { + echo json_encode(benchmarkDatabase()); + exit; + } + + // 3. Volledige Server Benchmark Suite + if ($_GET['action'] === 'bench_all') { + $cpu = benchmarkCPU(); + $mem = benchmarkMemory(); + $disk = benchmarkDiskIO(); + $str = benchmarkStringJSON(); + $db = benchmarkDatabase(); + $opcache = getOpcacheInfo(); + + // Bereken gewogen Server Score (0-100) + $score = 0; + + // CPU Score (max 25) + $cpuOps = $cpu['raw_ops'] ?? 0; + $score += min(25, round(($cpuOps / 150000) * 25)); + + // Memory Score (max 20) + $memOps = $mem['raw_ops'] ?? 0; + $score += min(20, round(($memOps / 200000) * 20)); + + // Disk Score (max 25) + $writeSpd = $disk['write_speed_mb_s'] ?? 0; + $score += min(25, round(($writeSpd / 300) * 25)); + + // String/JSON Score (max 15) + $strOps = $str['raw_ops'] ?? 0; + $score += min(15, round(($strOps / 35000) * 15)); + + // DB / OPcache Score (max 15) + if ($db['status'] === 'success') { + $dbTps = $db['raw_tps'] ?? 0; + $score += min(15, round(($dbTps / 20000) * 15)); + } else { + $score += ($opcache['enabled'] ? 12 : 8); + } + + $finalScore = max(35, min(100, $score)); + + // Grade toekenning + if ($finalScore >= 90) { + $grade = 'A+'; + $rating = 'Superieur (Enterprise Snelheid)'; + $color = '#34d399'; + } elseif ($finalScore >= 80) { + $grade = 'A'; + $rating = 'Uitstekend (Zeer Snelle Server)'; + $color = '#38bdf8'; + } elseif ($finalScore >= 70) { + $grade = 'B'; + $rating = 'Goed (Solide Hosting)'; + $color = '#fbbf24'; + } else { + $grade = 'C'; + $rating = 'Voldoende (Basis Hosting)'; + $color = '#f87171'; + } + echo json_encode([ 'status' => 'success', 'md5' => md5($input), 'sha256' => hash('sha256', $input), 'base64' => base64_encode($input), 'length' => mb_strlen($input) + 'score' => $finalScore, + 'grade' => $grade, + 'rating' => $rating, + 'color' => $color, + 'cpu' => $cpu, + 'memory' => $mem, + 'disk' => $disk, + 'string_json' => $str, + 'db' => $db, + 'opcache' => $opcache, + 'timestamp' => date('d-m-Y H:i:s') ]); exit; } echo json_encode(['status' => 'error', 'message' => 'Onbekende actie']); + // 4. Server Specificaties & Audit + if ($_GET['action'] === 'server_specs') { + echo json_encode([ + 'php_version' => PHP_VERSION, + 'sapi' => php_sapi_name(), + 'os' => PHP_OS_FAMILY . ' (' . PHP_OS . ')', + 'architecture' => (PHP_INT_SIZE * 8) . '-bit', + 'memory_limit' => ini_get('memory_limit'), + 'max_execution_time' => ini_get('max_execution_time') . 's', + 'upload_max_filesize' => ini_get('upload_max_filesize'), + 'post_max_size' => ini_get('post_max_size'), + 'opcache' => getOpcacheInfo(), + 'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Onbekend', + 'extensions' => [ + 'curl' => extension_loaded('curl'), + 'openssl' => extension_loaded('openssl'), + 'pdo_mysql' => extension_loaded('pdo_mysql'), + 'pdo_sqlite' => extension_loaded('pdo_sqlite'), + 'mbstring' => extension_loaded('mbstring'), + 'gd' => extension_loaded('gd'), + 'zip' => extension_loaded('zip') + ] + ]); + exit; + } + + echo json_encode(['status' => 'error', 'message' => 'Onbekend verzoek']); exit; } date_default_timezone_set('Europe/Amsterdam'); $serverTime = date('H:i:s'); $phpVersion = PHP_VERSION; +$serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? 'Apache / Nginx'; ?> @@ -56,16 +381,25 @@ $phpVersion = PHP_VERSION; Web & PC Studio - Interactive Dev Lab + Web & PC Studio - Webserver Benchmark & Dev Lab @@ -431,24 +1102,43 @@ $phpVersion = PHP_VERSION; Web & PC Studio
Dev Lab • v2.0
+
+ +
+

Interactief Developer Lab

+ +
+

Webserver Performance Suite

Geavanceerde demonstratie van server-side PHP computing, asynchrone AJAX communicatie en real-time HTML5 Canvas/Web Audio API rendering. + Voer diepgaande diagnostische server benchmarks uit om CPU-rekenkracht, Disk I/O schrijf/leessnelheid, geheugenbandbreedte en gelijktijdige request-capaciteit van www.webenpcstudio.nl te meten.

+
@@ -460,6 +1150,11 @@ $phpVersion = PHP_VERSION; PHP Server Benchmark PHP + +
+
+
+ Volledige Webserver Benchmark

Laat de server 75.000 cryptografische SHA-256 cycli berekenen en meet de execution time & piekgeheugen. @@ -471,20 +1166,84 @@ $phpVersion = PHP_VERSION;

Executietijd
-- ms
+
+ Test in één geautomatiseerde cyclus de CPU, NVMe/SSD Disk I/O, RAM doorvoer, JSON parsing en in-memory SQLite database. +
+
+ + +
+
+
+
+
+ + +
+
+ -- + / 100 +
+
+
Klaar
+
Klik start voor meting
+
+
+
+ + +
+ +
+
+
🚀 CPU & Math
+ 80k Math + 40k SHA +
+
Rekenkundige algoritmes en cryptografische hashing op de webserver CPU.
+
+
+
Bewerkingen / s
+
--
Bewerkingen / sec
--
+
+
Duur
+
-- ms
Piekgeheugen
-- MB
+
+ +
+ + +
+
+
💾 Disk I/O Snelheid
+ 3 MB Chunk R/W +
+
Fysieke schrijf- en leessnelheid naar de tijdelijke serveropslag (SSD/NVMe).
+
+
+
Schrijfsnelheid
+
-- MB/s
Iteraties
75.000
+
+
Leessnelheid
+
-- MB/s
+
@@ -493,8 +1252,23 @@ $phpVersion = PHP_VERSION;
📈 Live Latency Visualizer + +
+
+
🧠 RAM Doorvoer
+ 50k Associative Array +
+
Allocatie, manipulatie en serialisatie van complexe datastructuren in het werkgeheugen.
+
+
+
Doorvoer / s
+
--
Klaar voor test +
+
Piekgeheugen
+
-- MB
+

Meet real-time round-trip latency tussen browser en de Apache/PHP webserver. @@ -503,6 +1277,7 @@ $phpVersion = PHP_VERSION; +

@@ -513,29 +1288,61 @@ $phpVersion = PHP_VERSION; Client Hardware & GPU
Client Info + +
+
+
📦 String & JSON
+ 15k JSON Records
Grafische kaart (GPU): Detecteren... +
JSON encoding, decoding en RegEx parsing op gestructureerde data.
+
+
+
Records / s
+
--
CPU Cores / Threads: -- +
+
Payload Omvang
+
-- KB
Schermresolutie: -- +
+ +
+ + +
+
+
🗄️ Database RAM I/O
+ SQLite :memory: +
+
2.500 transacties met inserts, indexeringen en aggregatiequeries.
+
+
+
Transacties / s
+
--
Verbindingstype: -- +
+
Query Tijd
+
-- ms
Canvas WebGL Versie: --
+
@@ -546,6 +1353,11 @@ $phpVersion = PHP_VERSION; Live String & Hashing
Real-time + +
+
+
⚙️ Server Configuratie
+ PHP
@@ -553,25 +1365,92 @@ $phpVersion = PHP_VERSION; MD5 ... + + + + + + + + + + + + + + + + + +
Server Software:
PHP Memory Limit:
Max Execution Time:s
OPcache Status:Detecteren...
+ +
+
+ + +
+
+
+

🌐 Gelijktijdige HTTP Requests (Stress & RPS Test)

+

+ Vuur gelijktijdige asynchrone AJAX aanroepen af om te zien hoe de webserver piekdrukte opvangt. +

SHA-256 ... +
+ + + +
Base64 ... +
+ + +
+ Kies het aantal calls en klik op "Start Burst". +
+ +
+
+
Requests Per Seconde
+
-- RPS
+
+
+
Totale Batch Duur
+
-- ms
+
+
+
Snelste Call
+
-- ms
+
+
+
Gemiddelde Latency
+
-- ms
+ + + + diff --git a/services.php b/services.php index 9527962..ddeb279 100644 --- a/services.php +++ b/services.php @@ -728,3 +728,4 @@ $phpVersion = PHP_VERSION; +