public function getSpace()
{
$matches = array();
$availIdx = 0;
$usedIdx = 0;
$nameIdx = 0;
if ('darwin' == strtolower(PHP_OS)) {
$sysctl = `df -kl`;
preg_match_all('/([a-zA-Z0-9\\/]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9%]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9%]+)\\s+(.*)/', $sysctl, $matches, PREG_SET_ORDER);
$availIdx = 4;
$usedIdx = 3;
$nameIdx = 9;
} else {
if ('linux' === strtolower(PHP_OS)) {
$sysctl = `df -l --block-size=1K`;
preg_match_all('/([a-zA-Z0-9\\/]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9%]+)\\s+(.*)/', $sysctl, $matches, PREG_SET_ORDER);
$availIdx = 4;
$usedIdx = 3;
$nameIdx = 6;
}
}
$result = array();
$blacklist = array('/boot', '/dev', '/run', '/run/lock', '/run/shm');
foreach ($matches as $match) {
if (count($result) > 2) {
break;
}
$avail = $match[$availIdx] + 0;
$user = $match[$usedIdx] + 0;
$name = $match[$nameIdx];
if (in_array($name, $blacklist)) {
continue;
}
//anything under 1gb
if (1000 * 1024 > $avail) {
continue;
}
$result[$name] = array('name' => '/' === $name ? '/' : basename($name), 'used' => $user, 'available' => $avail, 'size' => $user + $avail);
}
return array_values($result) ?: array();
}