在do ... while循环中,已用完的内存大小为134217728字节(尝试分配31989760字节) [英] Allowed memory size of 134217728 bytes exhausted (tried to allocate 31989760 bytes) In a do...while loop

查看:97
本文介绍了在do ... while循环中,已用完的内存大小为134217728字节(尝试分配31989760字节)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个do while代码,该代码到达API以从AWS Elastic search中获取数据.当我增加大小时,会出现内存错误.现在我已将大小减小到20,但是想作为cronjob遍历结果,但是失败了.我已将内存增加到4096,但是失败

I have a do while code that reaches to an API to get data from AWS Elastic search. When I increase size, I get memory error. Now I have reduced size to 20, but want to loop through the results as a cronjob yet, it fails. I have increased memory to 4096 yet, it fails

我的.ini文件中的内存限制增加了,但是失败了.由于它是cronjob,所以我不知道如何使用滚动.

I have increased memory limit in my .ini file, yet it fails. Since its a cronjob, I have no idea how to use scroll.

do {
  $transporter  = new TransporterController;
  $response = $transporter->dispatchSearch($paper->title, '55%', $size, $from, $rounds );
  $json_response = json_decode((string) $response->getBody(), true);
  $rounds = $json_response['rounds'];
  $from = $json_response['from'] + $json_response['size'];

  $response = $transporter->purify($response, $object);
  $impact_user_id = $paper->impact_user_id;
  $impact_type_id = 2;
  $response = $transporter->saveResult($response, $impact_user_id, $impact_type_id);
  $transporter->notifier($response, $user);
} while ($rounds > 1);

这个想法是让循环运行到最后一页.这是laravel cronjob.

The idea is for the loop to run to completion, until last page. This is a laravel cronjob.

推荐答案

以下是三种增加共享主机限制的方法:

Here are three methods to increase the limit on shared hosting:

  1. 只需在您遇到错误的行之前将其添加到以下行 文件

  1. Just add this below line to before line of you getting error in your file

 ini_set('memory_limit', '-1');

  • 如果有权访问您的PHP.ini文件,请更改PHP.ini中的行 如果您的行显示32M,请尝试64M:memory_limit = 64M;最大金额 脚本可能会消耗的内存(64MB)

  • If you have access to your PHP.ini file, change the line in PHP.ini If your line shows 32M try 64M: memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)

    如果您无权访问PHP.ini,请尝试将其添加到.htaccess中 文件:php_value memory_limit 64M

    If you don't have access to PHP.ini try adding this to an .htaccess file: php_value memory_limit 64M

    还要确保您的文件指针有效,并为模式传递"r"(=读取).

    Also make sure your file pointer is valid, and pass "r" (= reading) for mode.

    这篇关于在do ... while循环中,已用完的内存大小为134217728字节(尝试分配31989760字节)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆