Asm Arman
Asm Arman

Reputation: 379

Laravel Heroku Application error

I am developing a Laravel 5.4 app.I have deployed it to Heroku ,running on free dyno and everything was working fine.I am using google drive as my cloud storage.After uploading a file,size of 200 mb ,I am getting this error:

                          Application error

An error occurred in the application and your page could not be served.
 If you are the application owner, check your logs for details.

I have saved a .user.ini in my project root,which I have edited like this:

post_max_size = 450M

upload_max_filesize = 400M

memory_limit =800M

I have tried to tail the log,but failed to point out the error.

2017-09-08T14:11:11.641039+00:00 app[web.1]: 10.30.39.212 - - [08/Sep/2017:14:10:11 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Linux; U; Android 6.0.1; en-US; Redmi Note 3 Build/MMB29M) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 UCBrowser/11.4.2.995 U3/0.8.0 Mobile Safari/534.30
2017-09-08T14:11:11.640651+00:00 app[web.1]: [Fri Sep 08 14:11:11.639951 2017] [proxy_fcgi:error] [pid 199:tid 140229860124416] (70007)The timeout specified has expired: [client 10.30.39.212:29863] AH01075: Error dispatching request to : (polling)
2017-09-08T14:11:31.916721+00:00 app[web.1]: [Fri Sep 08 14:11:31.916070 2017] [proxy_fcgi:error] [pid 119:tid 140229692311296] (70007)The timeout specified has expired: [client 10.178.162.66:30441] AH01075: Error dispatching request to : (polling)
2017-09-08T14:11:31.916923+00:00 app[web.1]: 10.178.162.66 - - [08/Sep/2017:14:10:31 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Linux; U; Android 6.0.1; en-US; Redmi Note 3 Build/MMB29M) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 UCBrowser/11.4.2.995 U3/0.8.0 Mobile Safari/534.30
2017-09-08T14:16:36.566647+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=namepedia.herokuapp.com request_id=18348fb3-4aa1-44d1-84e0-9944c0e3ca90 fwd="119.30.32.102" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=http
2017-09-08T14:17:06.636366+00:00 app[web.1]: 10.142.142.206 - - [08/Sep/2017:14:16:06 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
2017-09-08T14:17:06.636209+00:00 app[web.1]: [Fri Sep 08 14:17:06.634709 2017] [proxy_fcgi:error] [pid 199:tid 140229964785408] (70007)The timeout specified has expired: [client 10.142.142.206:33015] AH01075: Error dispatching request to : (polling)
2017-09-08T14:17:19.864896+00:00 heroku[web.1]: Process running mem=588M(110.3%)
2017-09-08T14:17:19.864994+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2017-09-08T14:17:40.187463+00:00 app[web.1]: 10.13.226.198 - - [08/Sep/2017:14:06:26 +0000] "POST /google HTTP/1.1" 200 42 "http://namepedia.herokuapp.com/test" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
2017-09-08T14:17:40.180242+00:00 heroku[router]: at=info method=POST path="/google" host=namepedia.herokuapp.com request_id=b5602546-0837-487b-b024-ab8686063d12 fwd="182.48.66.118" dyno=web.1 connect=1ms service=673737ms status=200 bytes=989 protocol=http

Memory Quota Exceeded

File Upload Controller:

public function fileupolad(Request $request){

$files = $request->file('files');

if($request->hasFile('files')){


foreach ($files as $file) {

   $filedata=new NameFile;

  $subject = $request->input('subject');
  $type = $request->input('type');

  $extension = $file->getClientOriginalExtension();
  $name = $file->getClientOriginalName();

  $onlyname=basename($file->getClientOriginalName(), '.'.$file-
  >getClientOriginalExtension());

   $myfile=Storage::disk('google')->put($name,File::get($file));

   $listContents = Storage::disk('google')->listContents();

  $fileid = $this->getId($listContents, 'filename', $onlyname);

  $id = $fileid['path'];
  $filedata->file=$file->getClientOriginalName();;

   $filedata->subject_id=$subject;

   $filedata->fileid=$id;
   $filedata->type=$type;
   $filedata->extension=$extension;

   $filedata->save();

}

}

}

Update:

I have changed the Upload controller like this:

$myfile=Storage::disk('google')->put($name,fopen($file,'r+'));

While uploading file,If anyone tries to go into my site they are facing Application Error.

Now,I am getting this error log. Another Error Log

2017-09-08T16:38:04.910262+00:00 app[web.1]: 10.229.116.254 - - [08/Sep/2017:16:37:04 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
2017-09-08T16:38:38.677784+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=namepedia.herokuapp.com request_id=2bb46915-8ad8-4de8-9208-c4eb7c9a92d6 fwd="119.30.32.102" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=http
2017-09-08T16:38:40.006721+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=namepedia.herokuapp.com request_id=6fead786-23fa-4f3c-b2b0-d459a0a48d84 fwd="119.30.32.102" dyno=web.1 connect=1ms service=1ms status=200 bytes=1386 protocol=http
2017-09-08T16:38:40.004373+00:00 app[web.1]: 10.61.201.223 - - [08/Sep/2017:16:38:40 +0000] "GET /favicon.ico HTTP/1.1" 200 1150 "http://namepedia.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
2017-09-08T16:39:08.741910+00:00 app[web.1]: 10.71.219.155 - - [08/Sep/2017:16:38:08 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
2017-09-08T16:39:08.741755+00:00 app[web.1]: [Fri Sep 08 16:39:08.741069 2017] [proxy_fcgi:error] [pid 115:tid 140448668550912] (70007)The timeout specified has expired: [client 10.71.219.155:16019] AH01075: Error dispatching request to : (polling)
2017-09-08T16:40:09.596516+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=namepedia.herokuapp.com request_id=d5c2b995-20d8-476c-8668-7810299c08c4 fwd="119.30.32.102" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=http
2017-09-08T16:40:12.326462+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=namepedia.herokuapp.com request_id=e8b549cb-4f2c-4e4e-b9e7-556e7929d653 fwd="119.30.32.102" dyno=web.1 connect=1ms service=4ms status=200 bytes=1386 protocol=http
2017-09-08T16:40:12.325932+00:00 app[web.1]: 10.99.212.2 - - [08/Sep/2017:16:40:12 +0000] "GET /favicon.ico HTTP/1.1" 200 1150 "http://namepedia.herokuapp.com/" "Mozilla/5.0 (Linux; U; Android 7.0; en-us; Redmi Note 4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.0.3
2017-09-08T16:40:39.659167+00:00 app[web.1]: [Fri Sep 08 16:40:39.658830 2017] [proxy_fcgi:error] [pid 113:tid 140448601425664] (70007)The timeout specified has expired: [client 10.16.227.159:59248] AH01075: Error dispatching request to : (polling)
2017-09-08T16:40:39.659415+00:00 app[web.1]: 10.16.227.159 - - [08/Sep/2017:16:39:39 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Linux; U; Android 7.0; en-us; Redmi Note 4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.0.3
2017-09-08T16:43:15.300665+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=namepedia.herokuapp.com request_id=b92d0da8-7eb3-4a4c-99aa-1a62a0e5e5b0 fwd="119.30.32.102" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http
2017-09-08T16:43:16.358949+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=namepedia.herokuapp.com request_id=f1b72007-6f8d-4b25-851e-3de9e093ff49 fwd="119.30.32.102" dyno=web.1 connect=1ms service=3ms status=200 bytes=1386 protocol=http
2017-09-08T16:43:16.362201+00:00 app[web.1]: 10.45.224.229 - - [08/Sep/2017:16:43:16 +0000] "GET /favicon.ico HTTP/1.1" 200 1150 "http://namepedia.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
2017-09-08T16:43:45.361523+00:00 app[web.1]: [Fri Sep 08 16:43:45.361082 2017] [proxy_fcgi:error] [pid 197:tid 140448567863040] (70007)The timeout specified has expired: [client 10.146.95.78:54462] AH01075: Error dispatching request to : (polling)
2017-09-08T16:43:45.361678+00:00 app[web.1]: 10.146.95.78 - - [08/Sep/2017:16:42:45 +0000] "GET / HTTP/1.1" 503 299 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36

Upvotes: 2

Views: 1660

Answers (1)

Joel Clermont
Joel Clermont

Reputation: 365

The problem is that you're reading the file into memory before saving it into your storage disk. There's a much simpler method for doing this that uses streaming by default and gets around any memory issues. I've tested this successfully with a 1GB file upload on a free Heroku dyno and there are no memory or locking issues.

Note, this example uses S3, but if you're using the Flysystem driver for Google it's the same basic concept. The key is that we're not creating a variable that reads in the full file, we're simply handing off the file from the Request directly to storage. By default, this gives us the $path back, so your extra call to listContents() can be avoided as well

    public function store(Request $request)
    {
        if ($request->hasFile('file')) {

            $path = $request->file('file')->store('/', 's3');

            return $path;
        }

    }

The only other thing to make sure of is that your php.ini overrides (in .user.ini) match the maximum file sizes you wish to support.

Upvotes: 2

Related Questions