当前位置:网站首页>PHP get (remote) large file method record
PHP get (remote) large file method record
2022-06-12 10:30:00 【P P PHP】
Usually PHP Error getting file , Will use file_get_contents(). But when getting large files , May report such a mistake :
Allowed memory size of 134217728 bytes exhausted (tried to allocate 49422336 bytes)This is because file_get_contents() Error getting file , Will put the contents of the file into a string , When the string size exceeds php.ini In the setting of memory_limit When parameters are , It's a mistake . The solution is to change the parameter a little larger , It's usually 128M, It can be modified a little larger . But you need to restart the server after the modification , It's troublesome . You can also change this value dynamically , Use ini_set. I use the following method to solve :
$handle = fopen(" Remote file address ", "rb");
$fp = fopen('vv.mp4', 'w');// Open a file ,
while (!feof($handle)) { // Cycle through remote files
$contents = '';
$contents = fread($handle, 1048576);// Each read 1M
fwrite($fp, $contents);// Writes the contents of a remote file to an open vv.mp4 file
}
fclose($handle);
fclose($fp);In this way, even the largest file can be read , It's just that there are more cycles , Take longer .
边栏推荐
- Golang start service background daemon
- Halcon combined with C # to detect surface defects -- affine transformation (III)
- 1268_ Implementation of FreeRTOS task context switching
- Php:redis uses geospatial
- CONDA install tensorflow test tensorflow
- [CEGUI] resource loading process
- Leetcode2154. Multiply the found value by 2 (binary search)
- Remote link software xshell and xftp download address
- The solution of Lenovo notebook ThinkPad t440 WiFi dropping all the time
- MySQL implements split method
猜你喜欢

Raw socket usage

Valentina Studio Pro for Mac(mac数据库管理软件)

Amélioration de la 3dsc par HSC

On 3dsc theory and application of 3D shape context feature
![[experiment] MySQL master-slave replication and read-write separation](/img/aa/7d0799013ff749cacf44ba3b773dff.png)
[experiment] MySQL master-slave replication and read-write separation

np. Meshgrid() function and coordinate position generation in 3D space and numpy Introduction to repeat() function

Pagoda chevereto1.6.2 the latest version of stepping on the pit tutorial in Chinese
![Reverse analysis of Huawei housekeeper software [transfer]](/img/85/7af372808e75f8791936c59918466f.jpg)
Reverse analysis of Huawei housekeeper software [transfer]

MQTT 协议中文版

2022淘宝618超级喵运会玩法来了 超级喵运会有哪些攻略方法
随机推荐
VSCode代码调试技巧
2022京东618预售定金怎么退?京东618定金能退吗?
[CEGUI] window environment compilation
PHP interface generates cache and MD5 encryption uniformly
High performance computing framework for image processing
验收标准到底是不是测试用例?
Win10 professional edition user name modification
Introduction to IOT
Introduction to encoding formats (ASCII, Unicode and UTF-8)
Properties Chinese garbled code
Circuitbreaker fuse of resilience4j - Summary
远程桌面不能复制粘贴解决办法
MQTT 协议中文版
2022 JD 618 Comment rembourser le dépôt de pré - vente? Le dépôt JD 618 peut - il être remboursé?
学生管理系统
Download Notepad++
Leetcode2154. 将找到的值乘以 2(二分查找)
Golang start service background daemon
Is the acceptance standard a test case?
PHP generate schedule