dry69034 2015-04-19 18:12
浏览 30

允许的内存大小大于所需但丢失致命错误

I am trying to use file_get_contents on a file but get the error below:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 187260544 bytes) in /dir/public_html/dir/file.php on line 18

Unless I am mistaken the allowed maximum is greater than what I am trying to use so why the error? Is there another setting that needs to be taken into account?

  • 写回答

1条回答 默认 最新

  • donglei1699 2015-04-19 18:43
    关注

    The total memory used by your code cannot exceed your maximum memory allowed. If you call memory_get_usage (http://php.net/manual/en/function.memory-get-usage.php) just before you do file_get_contents you'll probably find that the amount there + the 187260544 btyes for the file you want to load exceed the maximum allowed of 187260544 btyes.

    If so then you have other variables in memory using up a lot of memory. If you're loading other files into memory, consider clearing them (if you can) before loading this one (using unset) or consider streaming the file instead by reading it line by line using fgets (http://php.net/manual/en/function.fgets.php) or using PHP streams (http://php.net/stream).

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致