Laravel Route to Image in Storage got “Resource Limit Exceeded” in server (and it runs slow)

家住魔仙堡 提交于 2019-12-12 00:33:11

问题


Basically, i'm inspired by this question in building image manager feature for my blog in laravel. However, for unknown reason i keep hitting Resource Limit in the production server.

Here's my code:

//Migrations
        public function up()
            {
                Schema::create('images', function(Blueprint $table){
                  $table->increments('id');
                  $table->string('name')->unique();
                  $table->string('description')->nullable();
                  $table->string('image_path')->unique();
                  $table->string('mime');
                  // $table->integer('width')->unsigned();
                  // $table->integer('height')->unsigned();
                  $table->integer('filesize')->unsigned();
                  $table->timestamps();
                });
            }
    //Route
        Route::get('images/{path}', [
          'as'   => 'images',
          'uses' => 'Common\ImageController@respond'
          ]);
    //Controller
        protected function respond($name)
            {
              $path         = storage_path('/app/images/') . $name;
              if(!Storage::exists('/images/' . $name))
              {
                //if it did not exists in storage, just throw 404
                return abort(404);
              }
              //assume image_path as unique
              $image_entity = ImageEnt::where('image_path', '=', $name)->first();
              if($image_entity != null)
              {
                if($image_entity->mime != null)
                {
                  //200 = HTTP OK
                  return (new Response(Storage::get('/images/' . $name), 200))->header('Content-type', $image_entity->mime);
                }
              }
              return Response()->download($path);
            }

Server specification:

  • Shared Hosting
  • RAM 512 (max php memory also 512)
  • PHP max execution time 30

回答1:


It could be your PHP config, images tend to be large in size and the default limit in PHP is 2MB. Try ini_set('upload_max_filesize', '10M');



来源:https://stackoverflow.com/questions/32107486/laravel-route-to-image-in-storage-got-resource-limit-exceeded-in-server-and-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!