当前位置:网站首页>PHP efficiently reads large files and processes data
PHP efficiently reads large files and processes data
2022-04-23 16:49:00 【Dai Yuanpei】
<?php
// Direct use file() Fatal error will be reported Out of memory ; Such as $file = file($file);
// Wrong content Depending on memory_limit To configure
// Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 840860368 bytes) in /home/work/*.php on line *
// php bigFileRead.php test.txt
if(!isset($argv[1])){
echo 'The first parameter is null. =>>> [php bigFileRead.php 1.txt]'.PHP_EOL;die;
}else{
$file = $argv[1];
if(!file_exists($file)){
echo 'file does not exist.'.PHP_EOL;die;
}
}
function effReadFile($path){
if($handle = fopen($path, 'r')){
// Function to check whether the end of the file has been reached
while(!feof($handle)){
yield trim(fgets($handle));
}
fclose($handle);
}
}
// Read big papers Use
$glob = effReadFile($file);
while ($glob->valid()) {
// Current line text
$line = $glob->current();
// Process data line by line
echo $line.PHP_EOL;
// Point to next , It can't be less
$glob->next();
}
版权声明
本文为[Dai Yuanpei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231643577318.html
边栏推荐
- Gartner 發布新興技術研究:深入洞悉元宇宙
- Nacos detailed explanation, something
- 博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
- Detailed explanation of file operation (2)
- 批量制造测试数据的思路,附源码
- Selenium IDE and XPath installation of chrome plug-in
- DanceNN:字节自研千亿级规模文件元数据存储系统概述
- Zhimeng dedecms security setup Guide
- Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
- Getting started with JDBC
猜你喜欢
How much do you know about the process of the interview
JMeter installation tutorial and solutions to the problems I encountered
G008-hwy-cc-estor-04 Huawei Dorado V6 storage simulator configuration
PyTorch:train模式与eval模式的那些坑
阿里研发三面,面试官一套组合拳让我当场懵逼
RAID磁盘阵列与RAID5的创建
Zhongang Mining: Fluorite Flotation Process
Nacos detailed explanation, something
Gartner announces emerging technology research: insight into the meta universe
面试百分百问到的进程,你究竟了解多少
随机推荐
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
DDT + Excel for interface test
Differences between MySQL BTREE index and hash index
Project framework of robot framework
Derivation of Σ GL perspective projection matrix
Gartner publie une étude sur les nouvelles technologies: un aperçu du métacosme
SQL database
Summary according to classification in sail software
How to build tiktok user trust and drive fan growth
Execution plan calculation for different time types
STM32__03—初识定时器
【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......
Installing labellmg tutorial in Windows
博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
Gartner announces emerging technology research: insight into the meta universe
Report FCRA test question set and answers (11 wrong questions)
Cartoon: what are IAAs, PAAS, SaaS?
On the value, breaking and harvest of NFT project
NVIDIA显卡驱动报错
Idea of batch manufacturing test data, with source code