首页 > 解决方案 > 数据超过 2MB 的发布请求出现错误 Heroku

问题描述

我的 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 的数据时,它都会显示内部服务器错误。

标签: phpcodeigniterpostheroku

解决方案


对于那些尝试过.user.ini解决方案(https://stackoverflow.com/a/28897926/7092969)但它不起作用的人:

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

  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. 干杯! :)


推荐阅读