Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

php录制直播内存持续消耗导致中断

最近用php写了个脚本抓取直播流,用的是guzzle的请求库。请求直播地址会返回一个流,我使用以下代码保存直播流:
$f = fopen($fn,'w+');
$s = Utils::stream_for($f);
$bufsize=1024*1024*10;
while(!$resp->eof()){
$data=$resp->read($bufsize);
$s->write($data);
}
我同时监控写入文件的大小,发展文件是增长的,运行一段时间后报出allow memory size错误,报错的字节数和写入的文件大小相差不大。请问内存不足是因为每次读取都申请了新的内存吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

已使用原生fopen解决


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...