douwu5009 2017-04-18 05:44
浏览 196

使用ini_set时遇到的问题('memory_limit',' - 1')

I would like to know, is there any issues(bad to server) while using ini_set('memory_limit', '-1') on number of occasions?

The reason why I need to know this is, I'm now working in a project where use of join queries is high. We are only fetch required data's to avoid maximum load but in some situation where data exceeds 20000+ record, execution dies & shows 500 (Internal Server Error).

I know Error 500 may be cause of lot other issues, so I have checked it & found the reason was because of PHP execution memory limit exceeding(256M). When I set ini_set('memory_limit', '-1') on my code, query executed correctly.

The above explanation is just a situation/scenario, no need to consider that & Yes, I agree that using ini_set('memory_limit', '-1') is a bad practice. So, my question is clearly to know is there any issue on using ini_set('memory_limit', '-1') multiple times on different sections of a project (like sever issues or so). If yes, what are they?

  • 写回答

1条回答 默认 最新

  • drau67562 2017-04-18 06:42
    关注

    ini_set will set the configuration option during the script's execution, and will be restored at the script's ending.

    so ini_set will only works on the current php process. The next time a request coming, a new php process will read php.ini first to get the memory_limit and then you can use ini_set to set the value to -1.

    you can use ini_get to check memory_limit to avoid set memory_limit multiple times, and check the return value of ini_set to ensure success.

    using ini_set('memory_limit', '-1') is a bad idea. Try to use pagination to avoid fetch all data at a time.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用