PHP生成大量HTML文件,如何处理内存超出

WBOY
Release: 2016-06-13 12:20:24
Original
1593 people have browsed it

PHP生成大量HTML文件,如何避免内存超出

<br />ob_start ();<br />require 'xxx.php';<br />$temp = ob_get_contents ();<br />ob_end_clean ();<br />$fp = fopen ( $path, 'w' );<br />	fwrite ( $fp, $temp );<br />	fclose ( $fp );<br />
Copy after login


我现在要生成1万条数据,循环调用以上代码,但提示内存超出,该如何改写这个程序。(不修改内存,从代码上处理)

在某些CMS看到的是分批处理,生成HTML,又该如何去写?
------解决思路----------------------
分批执行,就不存在你说的问题了。
$total = 10;<br />$s = 0;<br />if (isset ( $_GET ['s'] )) {<br />        $s = &$_GET ['s'];<br />}<br />$per = $s + 5; // 每次循环5条<br />if ($per > $total) { // 如果下次循环会超过总数,就让他只能循环到总数<br />        $per = &$total;<br />}<br />while ( $s < $per ) {<br />        echo ++ $s;<br />        echo '<br>';<br />}<br />echo '<hr>';<br />echo $s;<br />if ($s < $total) {<br />        echo "<script>window.location.href='?s=$s'</script>";<br />}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!