日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

fopen吃内存吗 php,file_get_contents = PHP致命错误:允许的内存耗尽

發(fā)布時間:2024/7/23 php 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 fopen吃内存吗 php,file_get_contents = PHP致命错误:允许的内存耗尽 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我沒有處理大文件的經(jīng)驗,所以我不確定該怎么辦。我試圖使用 file_get_contents 讀取幾個大文件;任務是使用

preg_replace() 清潔和修補它們。

我的代碼在小文件上運行良好;但是,大文件(40 MB)觸發(fā)內(nèi)存耗盡錯誤:

PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 41390283 bytes)

我當時在考慮使用 fread(), 但是我不確定那也行。有解決此問題的方法嗎?

感謝您的輸入。

這是我的代碼:

error_reporting(E_ALL);

##get find() results and remove DOS carriage returns.

##The error is thrown on the next line for large files!

$myData = file_get_contents("tmp11");

$newData = str_replace("^M", "", $myData);

##cleanup Model-Manufacturer field.

$pattern = '/(Model-Manufacturer:)(\n)(\w+)/i';

$replacement = '$1$3';

$newData = preg_replace($pattern, $replacement, $newData);

##cleanup Test_Version field and create comma delimited layout.

$pattern = '/(Test_Version=)(\d).(\d).(\d)(\n+)/';

$replacement = '$1$2.$3.$4 ';

$newData = preg_replace($pattern, $replacement, $newData);

##cleanup occasional empty Model-Manufacturer field.

$pattern = '/(Test_Version=)(\d).(\d).(\d) (Test_Version=)/';

$replacement = '$1$2.$3.$4 Model-Manufacturer:N/A--$5';

$newData = preg_replace($pattern, $replacement, $newData);

##fix occasional Model-Manufacturer being incorrectly wrapped.

$newData = str_replace("--","\n",$newData);

##fix 'Binary file' message when find() utility cannot id file.

$pattern = '/(Binary file).*/';

$replacement = '';

$newData = preg_replace($pattern, $replacement, $newData);

$newData = removeEmptyLines($newData);

##replace colon with equal sign

$newData = str_replace("Model-Manufacturer:","Model-Manufacturer=",$newData);

##file stuff

$fh2 = fopen("tmp2","w");

fwrite($fh2, $newData);

fclose($fh2);

### Functions.

##Data cleanup

function removeEmptyLines($string)

{

return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);

}

?>

總結(jié)

以上是生活随笔為你收集整理的fopen吃内存吗 php,file_get_contents = PHP致命错误:允许的内存耗尽的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。