title: calling a php function that is outside the controller using laravel 4.2
body: <p>so I have this function that gets the remaining memory where my Laravel project is located. The thing is there are two controllers that need to check the remaining memory.</p>
  
  <p>Here is what it looks like it is just inside my controller</p>
  
  <pre><code>private function convGB($bytes, $unit = "", $decimals = 2)
  {
       $units = array('B' =&gt; 0, 'KB' =&gt; 1, 'MB' =&gt; 2, 'GB' =&gt; 3, 'TB' =&gt; 4, 
       'PB' =&gt; 5, 'EB' =&gt; 6, 'ZB' =&gt; 7, 'YB' =&gt; 8);
  
       $value = 0;
       if ($bytes &gt; 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 &lt; 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 &gt;= 1073741824)
      {
          $ds = number_format($ds / 1073741824, 2) . ' GB';
      }
      elseif ($ds &gt;= 1048576)
      {
          $ds = number_format($ds / 1048576, 2) . ' MB';
      }
      elseif ($ds &gt;= 1024)
      {
          $ds = number_format($ds / 1024, 2) . ' KB';
      }
      elseif ($ds &gt; 1)
      {
          $ds = $ds . ' B';
      }
      elseif ($ds == 1)
      {
          $ds = $ds . ' B';
      }
      else
      {
          $ds = '0 size';
      }
  
      if ($fs &gt;= 1073741824)
      {
          $fs = number_format($fs / 1073741824, 2) . ' GB';
      }
      elseif ($fs &gt;= 1048576)
      {
          $fs = number_format($fs / 1048576, 2) . ' MB';
      }
      elseif ($fs &gt;= 1024)
      {
          $fs = number_format($fs / 1024, 2) . ' KB';
      }
      elseif ($fs &gt; 1)
      {
          $fs = $fs . ' B';
      }
      elseif ($fs == 1)
      {
          $fs = $fs . ' B';
      }
      else
      {
          $fs = '0 size';
      }
  
      $converted = $this-&gt;convGB($ffs);
  
      return array( $ds , $fs , $converted);
  }
  </code></pre>
  
  <p>So I wanted to put the function in an external PHP so that I would just call it when I needed it. Any ideas on how to do this? Thanks so much! </p>