【问题标题】:Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in PHPPHP 中允许的内存大小为 134217728 字节已用尽(尝试分配 32 字节)
【发布时间】:2015-06-09 09:11:16
【问题描述】:

当我尝试将 file_get_contents 输出存储到 obj 中时,我的代码遇到问题。

$json = file_get_contents($url);
$obj = json_decode($obj);

我不允许更改 ini.php 中的内存大小,因为它在服务器上。还有其他解决方案吗?

【问题讨论】:

标签: php memory


【解决方案1】:

你有一个简单的错字:

$json = file_get_contents($url);
$obj = json_decode($json);

【讨论】:

  • 糟糕,是的,在此处发布问题时出现拼写错误。但我仍然有这个问题。
【解决方案2】:

您是否尝试过其他增加内存限制的选项? 喜欢

ini_set('memory_limit', '-1'); //change the -1 to a value that acommodates to your use case
$json = file_get_contents($url);
$obj = json_decode($json);

【讨论】:

    【解决方案3】:

    ini_set('memory_limit', '256M');

    或设置更大的内存

    【讨论】:

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