heroku / heroku-buildpack-php

Heroku's buildpack for PHP applications.

Home Page:https://devcenter.heroku.com/categories/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code=H18 desc="Server Request Interrupted"

AugustoGCP opened this issue · comments

Hey mates, first of all, sorry about my bad English

Im following this instructions https://devcenter.heroku.com/articles/custom-php-settings#setting-the-document-root. I changed the Procfile and .user.ini file. I inserted this configurations

Procfile:

web: vendor/bin/heroku-php-apache2  intralists/public/

.user.ini:

upload_max_filesize = 2048M
memory_limit = 2048M
php_value[memory_limit] = 2048M
max_input_time = 100000 
max_execution_time = 100000

When I send my POST request and next run the command heroku logs. I see this error log

sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/dashboard/procedimento/update" host=intralists.herokuapp.com request_id=65d01fb0-f01a-49f1-a300-2bac22e132e3 fwd="187.32.246.81" dyno=web.1 connect=0ms service=160ms status=503 bytes=1075 protocol=http
2021-10-11T13:31:20.507678+00:00 app[web.1]: 10.1.39.246 - - [11/Oct/2021:13:31:20 +0000] "POST /dashboard/procedimento/update HTTP/1.1" 200 2 "http://intralists.herokuapp.com/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0
2021-10-11T13:31:20.986210+00:00 app[web.1]: [11-Oct-2021 13:31:20 UTC] PHP Warning:  Unknown: POST Content-Length of 8429095 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

I read about this error H18 on documentation and basicly what I understood was that error happen because the serve took too long time to answer and the connection is close. In local environment I changed the setting on php.ini and it's working very well, but I'm can't do the same it in Heroku.

Executing the file php.info where there's a function <?php phpinfo(); ?>, it's possible to see the settings correctely
image

I dont know if Im losing/forgetting something or dont understand exectely what is the problem. But the error H18 "Server Request Interrupted" still remain.

Somebody can help me how can I solve it?

The PHP warning message from your logs has the important hint:

POST Content-Length of 8429095 bytes exceeds the limit of 8388608 bytes

8388608 is exactly 8M, so you're probably not changing the setting in the right place.

Your .user.ini must be in the document root (so in intralists/public/), not in the root of the app.

Change the values to something lower first for testing (there might be a hardcoded upper limit inside PHP, not sure); these two lines are enough in intralists/public/.user.ini:

upload_max_filesize = 100M
post_max_size = 100M

However, I think you should use a different solution entirely, where you upload a file directly from the browser to e.g. an S3 bucket, and a background worker pulls it from there. This is possible with a suitable CORS configuration for the S3 bucket, and you then obtain a pre-signed destination URL for the browser on the server side (using the AWS SDK for PHP), and write that out to the file upload form. Once the upload to S3 is complete, a separate worker process can then pull the file from S3, handle it, etc.

This is a generally good practice, and not specific to Heroku. It prevents the upload from occupying a backend web process for the entire duration of the file transfer.

Keep in mind that on Heroku, your app also only has 30 seconds to process the file before a timeout occurs (https://devcenter.heroku.com/articles/request-timeout), and PHP-FPM by default will terminate child processes that are running a script for longer than 30 seconds, which IIRC includes input time (https://devcenter.heroku.com/articles/php-support#timeouts), but that part at least you could re-configure.