【问题标题】:Post request with data more than 2MB gets error Heroku数据超过 2MB 的发布请求出现错误 Heroku
【发布时间】:2018-11-23 22:28:37
【问题描述】:

我的 PHP 应用程序在 heroku 上运行。 php 应用程序正在运行代码点火器框架。 我有一个第三方合作伙伴将文件发送到我允许他们发布数据的功能。

它是 codeigniter 控制器上的一个普通 php 函数。

public function getting_third_party_data(){
// Fetching all information from the post request and saving to db
}

问题在于,每当他们发送低于 2MB 的数据时,它都能正常工作,但当超过 2MB 时,我的应用程序会发送内部服务器错误。

我联系了 heroku 的人,但他们在 2-3 周内停止回复,所以我在这里问。

我使用以下参数添加了.user.ini 文件

memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M

即使在此之后,每当我的应用收到超过 2MB 的数据时,它都会显示内部服务器错误。

【问题讨论】:

标签: php codeigniter post heroku


【解决方案1】:

对于那些尝试过.user.ini 解决方案(https://stackoverflow.com/a/28897926/7092969)但没有奏效的人:

我们的 Laravel 应用由 Apache 或 Nginx 执行。这可以通过根目录中的 Heroku Procfile 进行更改:

  1. 让我们在根目录下创建nginx.conf 并添加以下内容:
client_max_body_size 25M;

location / {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    # rewrite all to index.php
    rewrite ^(.*)$ /index.php/$1 last;
}

location ~ ^/index\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    # ensure that /index.php isn't accessible directly, but only through a rewrite
    internal;
}

  1. Procfile 内容设置为:
web: vendor/bin/heroku-php-nginx -C nginx.conf public/
  1. 重新部署 Heroku 应用

  2. 干杯! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 2021-03-02
    • 2015-05-29
    • 2019-05-03
    相关资源
    最近更新 更多