0
을 사용하여 컨트롤러 외부에있는 PHP 함수를 호출하므로 Laravel 프로젝트가있는 나머지 메모리를 가져 오는이 함수가 있습니다. 나머지 메모리를 확인해야하는 컨트롤러가 두 개 있습니다. 여기laravel 4.2
는
private function convGB($bytes, $unit = "", $decimals = 2)
{
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
$value = 0;
if ($bytes > 0)
{
if (!array_key_exists($unit, $units))
{
$pow = floor(log($bytes)/log(1024));
$unit = array_search($pow, $units);
}
$value = ($bytes/pow(1024,floor($units[$unit])));
}
if (!is_numeric($decimals) || $decimals < 0) {
$decimals = 2;
}
return sprintf('%.' . $decimals . 'f '.$unit, $value);
}
private function getMem()
{
$ds = disk_total_space(substr(base_path(), 0, 2));
$fs = disk_free_space(substr(base_path(), 0, 2));
$ffs = disk_free_space(substr(base_path(), 0, 2));
if ($ds >= 1073741824)
{
$ds = number_format($ds/1073741824, 2) . ' GB';
}
elseif ($ds >= 1048576)
{
$ds = number_format($ds/1048576, 2) . ' MB';
}
elseif ($ds >= 1024)
{
$ds = number_format($ds/1024, 2) . ' KB';
}
elseif ($ds > 1)
{
$ds = $ds . ' B';
}
elseif ($ds == 1)
{
$ds = $ds . ' B';
}
else
{
$ds = '0 size';
}
if ($fs >= 1073741824)
{
$fs = number_format($fs/1073741824, 2) . ' GB';
}
elseif ($fs >= 1048576)
{
$fs = number_format($fs/1048576, 2) . ' MB';
}
elseif ($fs >= 1024)
{
$fs = number_format($fs/1024, 2) . ' KB';
}
elseif ($fs > 1)
{
$fs = $fs . ' B';
}
elseif ($fs == 1)
{
$fs = $fs . ' B';
}
else
{
$fs = '0 size';
}
$converted = $this->convGB($ffs);
return array($ds , $fs , $converted);
}
그래서 내가 그것을 필요로 할 때 난 그냥 전화를 할 수 있도록 외부 PHP에서 함수를 넣고 싶어 그냥 내 컨트롤러의 내부처럼 보이는 것입니다. 이 작업을 수행하는 방법에 대한 아이디어가 있습니까? 정말 고마워!
그래서 기능을 사용하면 이동 하시겠습니까? 귀하의 코드 예제에서 두 가지를 볼 수 있습니다. – JRSofty
안녕하세요, 그냥'getMem' 함수를 사용합니다 – BourneShady