2015-07-13 40 views
0

我在Laravel上使用Glide,我對它有「小」的問題。當我通過outputImage()加載小圖像時,一切都很好。但是,當我嘗試加載 - 簡單 - 把圖像Laravel的1.6MB控制檯:Laravel滑出內存

Allowed memory size of 67108864 bytes exhausted (tried to allocate 14152 bytes) in C:\Users\displate\Documents\displate\vendor\intervention\image\src\Intervention\Image\Gd\Decoder.php on line 34 

我怎麼能簡單的解決呢?

我的代碼

壞的部分:

protected function get($path,$storage,$sizes,$prefix=''){ 
    ini_set('memory_limit', '64M'); // it's not working :< 
    if($this->check_variables($sizes)){ 
     $server=$this->prepare_server($storage,$prefix); 

     try{ 
      $server->getImageResponse($path); 

      $server->outputImage($path, $_GET); 
     } 
     catch(\Exception $e){ 
      $this->download_image($path,$storage); 

      $server->getImageResponse($path); 

      $server->outputImage($path, $_GET); 
     } 
    } 
    else{ 
     abort(404); 
    } 
} 

protected function prepare_server($storage_name,$prefix=''){ 
    $server = \League\Glide\ServerFactory::create([ 
        'source' => \Storage::disk($storage_name)->getDriver(), 
        'cache' => \Storage::disk($storage_name)->getDriver(), 
        'source_path_prefix' => $prefix, 
        'cache_path_prefix'  => $storage_name.'_cached', 

       ]); 

    $_GET['fit']='crop'; 
    $_GET['crop']='center'; 

    return $server; 
} 

回答

1

如果youre確保您的實際運行內存爲你想的原因,而不是從某些無限循環或其他錯誤,可以增加內存量該PHP可以通過執行以下操作來使用。

  • 找到您的Web服務器
  • 編輯php.ini文件中memory_limit參數(通常在一節所謂的資源限制)
  • 重啓Apache使用的php.ini文件。

它應該是這個樣子算賬:

memory_limit 128M 

如果您遇到問題,this看起來像一個很好的資源

64MB,這是你所擁有的,心不是那麼多。如果你有內存,Id將它固定在512M甚至1024M。

+0

內存限制幫助我,我現在使用512Mb – ventaquil