dongqiang2024 2019-01-07 09:05
浏览 333
已采纳

允许的内存大小为134217728字节耗尽(试图分配31989760字节)在do ... while循环中

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

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);

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

  • 写回答

1条回答 默认 最新

  • duan198299 2019-01-07 09:08
    关注

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

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

       ini_set('memory_limit', '-1');
      
    2. 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)

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题