Laravel到存储中的映像的路由“超出资源限制"在服务器上(它运行缓慢) [英] Laravel Route to Image in Storage got "Resource Limit Exceeded" in server (and it runs slow)
本文介绍了Laravel到存储中的映像的路由“超出资源限制"在服务器上(它运行缓慢)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我的灵感来自这个问题我在laravel中的博客.但是,由于未知原因,我一直在生产服务器中达到资源限制.
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.
这是我的代码:
//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);
}
服务器规范:
- 共享主机
- RAM 512(最大php内存也为512)
- PHP的最大执行时间为30
推荐答案
这可能是您的PHP配置,图像大小通常较大,PHP中的默认限制为2MB.尝试ini_set('upload_max_filesize', '10M');
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');
这篇关于Laravel到存储中的映像的路由“超出资源限制"在服务器上(它运行缓慢)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文