Home > Backend Development > PHP Tutorial > php在下载远程压缩包的时候,由于文件过大,先下载到内存导致内存崩溃

php在下载远程压缩包的时候,由于文件过大,先下载到内存导致内存崩溃

WBOY
Release: 2016-06-06 20:44:23
Original
1227 people have browsed it

php在下载远程压缩包的时候,由于文件过大,先下载到内存导致内存崩溃,求解决方法

<code>    ob_start (); //开启output buffering  
    readfile ( $file ); //将文件读取buffering中  
    $img = ob_get_contents (); //将buffering中的数据保存到变量当中,方便后续操作  
    ob_end_clean (); //关闭output buffering  
    $fp2 = @fopen ( $filename, "a" ); //打开目标文件(马上被写入数据的文件)  
    fwrite ( $fp2, $img ); //写入数据到文件当中  
    fclose ( $fp2 ); //关闭文件句柄  
</code>
Copy after login
Copy after login

回复内容:

php在下载远程压缩包的时候,由于文件过大,先下载到内存导致内存崩溃,求解决方法

<code>    ob_start (); //开启output buffering  
    readfile ( $file ); //将文件读取buffering中  
    $img = ob_get_contents (); //将buffering中的数据保存到变量当中,方便后续操作  
    ob_end_clean (); //关闭output buffering  
    $fp2 = @fopen ( $filename, "a" ); //打开目标文件(马上被写入数据的文件)  
    fwrite ( $fp2, $img ); //写入数据到文件当中  
    fclose ( $fp2 ); //关闭文件句柄  
</code>
Copy after login
Copy after login

http://stackoverflow.com/questions/6914912/streaming-a-large-file-using-php

加大PHP的内存使用 ini_set('memory_limit','1024M');

Related labels:
php
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