Php include and ob functions are in the loop. how can this problem be solved?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.