Php's include and ob functions cause the following program in a loop... foreach ($ arras $ value) {& nbsp; ob_start (); & nbsp; includetemplate ($ value ['filename']); & nbsp; $ messa php's include and ob functions cause
The program is roughly as follows:
...
Foreach ($ arr as $ value ){
Ob_start ();
Include template ($ value ['filename']);
$ Message = addslashes (trim (ob_get_contents ()));
Ob_end_clean ();
}
In this mode, if you run 5000 data records
Too Upload open files error
If the number of executions is 1000, no problem
How can this problem be solved?
------ Solution --------------------
Too open files is Too many open files
You should consider changing your mind, rather than include
------ Solution --------------------
We recommend that you check the usage of ob_start, ob_end_clean (), and ob_get_contents (). you can understand what is going on.
PHP code
Ob_start (); foreach ($ arr as $ value) {include template ($ value ['filename']); $ message = addslashes (trim (ob_get_contents ())); ob_end_clean ();};
------ Solution --------------------
Foreach ($ arr as $ value ){
Ob_start ();
Include template ($ value ['filename']);
$ Message = addslashes (trim (ob_get_contents ()));
Ob_end_clean ();
}
Do you generate static data like this?
Use request redirection for batch execution.
Demo of pseudocode
Trigger request: dosomeing. php? Page = 1 & per = 1000;
PHP code
$ Arr = $ data. limit (page-1) * $ per, per) foreach ($ arr as $ value) {ob_start (); include template ($ value ['filename']); $ message = addslashes (trim (ob_get_contents (); ob_end_clean () ;}$ page ++; header ('Location: dosomeing. php? Page = '. $ page.' & per = '. $ per)
------ Solution --------------------
Php version? 5.2.6?
It may be a php bug.
Change include to include_once.
Http://bugs.php.net/bug.php? Id = 45133