Fatal error: Allowed memory size- PHP expert advice needed
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 n开发者_Go百科eeded so this does not all accumulate in memory?
Thank You in advance
. .
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?
Unlike the command line interface, if you have output buffering set to automatic or your script has ob_start()
, you do need ob_flush()
AND flush()
to commit data to the browser output. Otherwise, only flush()
is necessary. This is the browser's behavior and the nature of HTTP connections.
精彩评论