PHP generates a large number of HTML files and how to avoid memory exceeding

Source: Internet
Author: User
PHP generates a large number of HTML files and how to avoid memory exceeding
ob_start ();require 'xxx.php';$temp = ob_get_contents ();ob_end_clean ();$fp = fopen ( $path, 'w' );fwrite ( $fp, $temp );fclose ( $fp );


Now I want to generate 10 thousand pieces of data and call the above code cyclically, but I am prompted that the memory is exceeded. how can I rewrite this program. (Process the code without modifying the memory)

In some CMS, we see batch processing, generating HTML, and how to write it?


Reply to discussion (solution)

No answer is answered after the weekend break.

Since it is "batch generation", should there be loops or iterations?
We recommend that you paste the iteration or loop part.
In general, unset variables that are not needed after variables are used should be one of the solutions.

It is difficult to analyze because the information is incomplete.
Furthermore, the garbage collection mechanism before and after PHP5.3 is different, so there is no unified standard.
We recommend that you configure the environment.

For example, if it is an infinite loop, the memory will exceed the threshold for a certain number of times. how can we let him cycle 100 times, release the memory, and then loop, so that the memory peak will not exceed the threshold?

It can be identified by one page. For example, 10 messages are generated and you can jump to the page. To the next 10. This way. It will not be executed on the same page for so long.

Batch execution is not a problem you mentioned.

$ Total = 10; $ s = 0; if (isset ($ _ GET ['s']) {$ s = & $ _ GET ['s'];} $ per = $ s + 5; // 5 if ($ per> $ total) in each loop {// if the total number in the next loop is exceeded, so that he can only cycle to the total number $ per = & $ total;} while ($ s <$ per) {echo ++ $ s; echo'
';} Echo ''; echo $ s; if ($ s <$ total) {echo" script window. location. href = '? S = $ s 'script ";}
Related Article

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.