【问题标题】:Allowed memory size of 134217728 bytes exhausted (tried to allocate 62926848 bytes)允许的内存大小 134217728 字节用尽(尝试分配 62926848 字节)
【发布时间】:2018-02-23 22:06:06
【问题描述】:

我在 laravel 5.5 中遇到了内存大小耗尽的问题。 它之前的意思是我的代码是 5.4 版本,但现在不行。 为此,我从 php.ini 文件 memory_limit 1024M 增加了内存大小。但不工作。 基本上我正在转换 Base64 文件格式文件,然后存储到我的 PC 或服务器的本地存储中。

控制器代码

    public static  function convertBase64ToFile ( $file   , $dir  )
{
    $pos  = strpos($file, ';');
    $type = explode(':', substr($file, 0, $pos))[1];
    $format = explode('/',$type);

    $exploded = explode(',', $file);

    $decoded = base64_decode($exploded[1]);

    if(str_contains($exploded[0], $format[1]))

    { $extension = $format[1];}

    $filename = str_random().'.'.$extension;

    $path = public_path().$dir.$filename;

    file_put_contents($path, $decoded);

    return $filename;
   }

消息:

"允许的内存大小为 134217728 字节已用尽(尝试分配 65015808 字节)", "exception": "Symfony\Component\Debug\Exception\FatalErrorException",

【问题讨论】:

  • 文件有多大?
  • 检查数学。我看到的是 134 MB,而不是 1024。
  • 查看 phpinfo 输出并检查 memory_limit 是否已更改。
  • 您应该能够完成这样的事情,而无需将整个文件加载到内存中。如果您能更好地描述$file 中的数据以及数据的来源,我应该能够提出更好的攻击计划。

标签: php wampserver laravel-5.5


【解决方案1】:

在 wamp 中,您有 2 个 php.ini 文件。一个在\wamp\bin\php\php.x.y.z,但这个仅用于CLI,第二个在\wamp\bin\apache\apache2.x.y\bin\。你应该检查第二个

【讨论】:

    猜你喜欢
    • 2016-04-18
    • 2013-08-09
    • 2021-12-29
    • 2017-07-23
    • 2014-11-20
    • 2017-10-30
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多