Reputation: 341
I don't understand how I can send a response to avoid Heroku's server error when uploading files that exceed 20mb.
I am using PHP 7.4/Laravel 8.x and I am receiving,
heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST
An H18 signifies that the socket connected, some data was sent as part of a response by the app, but then the socket was destroyed without completing the response.
It is terminating early due to Heroku's 30 second request limit.
I have configured my .user.ini file,
post_max_size = 100M
upload_max_filesize = 100M
max_input_time = 300
max_execution_time = 300
Am declaring it in the Procfile,
web: vendor/bin/heroku-php-apache2 -i .user.ini public/
I accept multiple files in my form,
<input style="display:none;" type="file" id="files" name="attachment[]" multiple required>
<label for="files" class="files-button" id="filesButton">Upload Images</label>
if the file is an image, I upload it
ini_set('memory_limit', '-1'); // more memory
if($request->hasFile('attachment')) {
$valid_exts = ['png', 'jpg', 'jpeg'];
foreach ($files as $file) {
$extension = $file->getClientOriginalExtension();
if (in_array($extension, $valid_exts)) {
Storage::disk('s3')->put("/model images/$url_name/", $file);
}
}
}
}
Is there any way around this 30 second forced timeout?
Upvotes: 0
Views: 1241
Reputation: 533
I'm running up with the same problem. As you say the connection is interrupted by a section of a large response.
Usually, an H18 indicates that a response has multiple stages - for instance, streaming chunks of a large response - and that one of those stages has thrown an error. https://devcenter.heroku.com/articles/error-codes#h18-server-request-interrupted
Docs suggest looking through the log files to determine which stage/chunk of the response it threw the error on and fixing that problem.
As far as configuring time out, Heroku says it's not possible.
The timeout value is not configurable. If your server requires longer than 30 seconds to complete a given request, we recommend moving that work to a background task or worker to periodically ping your server to see if the processing request has been finished. This pattern frees your web processes up to do more work, and decreases overall application response times. https://devcenter.heroku.com/articles/request-timeout#long-polling-and-streaming-responses
And suggest using a "direct" file upload, uploading it directly to an S3 from the browser. https://devcenter.heroku.com/articles/s3#file-uploads
Upvotes: 1