3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* get system resource precentages */ function serverStatus() { /* cpu usage */ $cpuUsage=NULL; exec('ps -aux', $processes); foreach($processes as $process){ $cols = split(' ', ereg_replace(' +', ' ', $process)); if (strpos($cols[2], '.') > -1){ $cpuUsage += floatval($cols[2]); } } $sysLoad = sys_getloadavg(); /* get raspberry pi temp */ $rawTemp = shell_exec('/opt/vc/bin/vcgencmd measure_temp'); /* trim temp= from the response */ $temp_c = round(str_replace("temp=", "", $rawTemp),2); $temp_f = round((($temp_c * 9) / 5) + 32,2); /* memory usage */ foreach(file('/proc/meminfo') as $ri) $m[strtok($ri, ':')] = strtok(''); /* displays memory used precentage */ $memory = 100 - round(($m['MemFree'] + $m['Buffers'] + $m['Cached']) / $m['MemTotal'] * 100); /* free memory in mB rounded to tenths */ $memoryFree = round($m['MemFree']/(1024), 2); /* Buffered memory in mB rounded to tenths */ $bufferedMem = round($m['Buffers']/(1024), 2); /* cached Memoty in mB and rounded to tenths */ $cachedMem = round($m['Cached']/(1024),2); /* total memory in mB rounded to tenths */ $TotleMem = round($m['MemTotal']/(1024),2); /* disk free space a gigabytes and rounded to tenths */ $freeSpace = round(disk_free_space("/")/(1024*1024*1024), 2); /* total disk space in gigabytes and rounded to tenths */ $totalSpace = round(disk_total_space("/")/(1024*1024*1024), 2); /* disk free space in precentage */ $freePrecent = round($freeSpace / $totalSpace * 100, 2); /* server uptime*/ $uptime = shell_exec("cut -d. -f1 /proc/uptime"); $days = floor($uptime/60/60/24); $hours = $uptime/60/60%24; $mins = $uptime/60%60; $secs = $uptime%60; /* current server time */ $obsTime= date("g:i a" ,time()).' on '.date("l, F d, Y" ,time()); /* build status array */ $status=array( 'cpu' => $cpuUsage.' %', 'system load' => $sysLoad, 'cpu temp_c' => $temp_c.' C', 'cpu temp_f' => $temp_f.' F', 'memory' => $memory.' %', 'memory free' => $memoryFree.' mB', 'buffered memory' => $bufferedMem.' mB', 'memory cached' => $cachedMem.' mB', 'total memory' => $TotleMem.' mB', 'free gb' => $freeSpace.' gB', 'free precent' => $freePrecent.' %', 'total gb' => $totalSpace.' gB', 'uptime' => $days.' days '.$hours.' hours '.$mins.' minutes and '.$secs.' seconds', 'observation time' => $obsTime ); return $status; }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1

preferences:
209.39 ms | 404 KiB | 325 Q