致命错误:允许的内存大小 - 需要 PHP 专家的建议
你好 我有一个带有我自己的类的 PHP 程序。我在办公室使用 Xampp 服务器。
它有 4 个基本部分: 1)程序读取一条mysql记录(“SELECT a,b,c.... 然后循环几次总计。
2)将一些变量回显到屏幕上(大约10个)
3)将一条记录插入到第二个mysql文件中(第一组的摘要)
4)清除变量(30个左右)
现在我已经阅读了很多关于这个主题的页面,包括大约15页这里。我知道我可以增加内存,但这不是我正在寻找的解决方案。 我现在第一个数据库中有大约 3,000 条记录,我预计它会增长 1000 倍。
我有多年的编程经验,能看出问题所在。在像“c”这样的语言中,当您执行这种循环时,结果会立即显示。但是对于 PHP,它会循环并且不会显示任何内容,直到操作结束或像这里一样停止。我知道那正在填满记忆。我无法显示任何变量,但可能很难调试。
那么我该如何解决这个问题呢?我查看了flush()和ob_flush()。这是否是所需要的,这样就不会全部累积在内存中?
先感谢您
。 。
Hello
I have a PHP program with my own classes. I am using a Xampp server in the office.
It has 4 basic parts:
1)The program reads one mysql record ("SELECT a, b, c....
then loops a few times to total.
2) echo some variables to the screen (about 10)
3) Insert a record into a second mysql file (summary of the first group)
4) Clear variables (30 or so)
Now I have read many pages on this topic including about 15 here. I know I can up the memory, but that is not the solution I am looking for.
I now have about 3,000 records in the first database and I expect it to grow 1000x that.
I have years of programing experience and can see the problem. In a language like "c" when you do this kind of loop, the results are displayed immediately. But with PHP it cycles and nothing is displayed until the operation is over or it stops like here. I know that is filling up the memory. I could not display any variables, but it might be difficult to debug.
So how do I resolve this? I looked at flush() and ob_flush(). Is that what is needed so this does not all accumulate in memory?
Thank You in advance
.
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不一次获取 5000 条记录,然后将其写入磁盘(就像缓存一样)。
我们也可以看一些代码吗?
Why don't you fetch 5000 records at a time, then write it to disk (like a cache).
Can we see some code too please?
与命令行界面不同,如果您将输出缓冲设置为自动或您的脚本具有
ob_start()
,则您确实需要ob_flush()
和flush()< /code> 将数据提交到浏览器输出。否则,只需要
flush()
。这是浏览器的行为和 HTTP 连接的本质。Unlike the command line interface, if you have output buffering set to automatic or your script has
ob_start()
, you do needob_flush()
ANDflush()
to commit data to the browser output. Otherwise, onlyflush()
is necessary. This is the browser's behavior and the nature of HTTP connections.