PHP YIELD使读取大文件变成可能
来源:互联网 发布:百度地图编辑软件 编辑:程序博客网 时间:2024/06/04 23:23
例子:摘自PHP手册
for the protection from the leaking of resources
see RFC https://wiki.php.net/rfc/generators#closing_a_generatorand use finnaly
sample code
function getLines($file) {
$f = fopen($file, 'r');
try {
while ($line = fgets($f)) {
yield $line;
}
} finally {
fclose($f);
}
}
foreach (getLines("file.txt") as $n => $line) {
if ($n > 5) break;
echo $line;
}
0 0
- PHP YIELD使读取大文件变成可能
- PHP 读取大文件
- PHP读取大文件
- PHP读取大文件
- php读取操作大文件
- PHP 读取大文件 SplFileObject
- php读取大文件详解
- php读取操作大文件
- php读取操作大文件
- php读取大文件详解
- php读取操作大文件
- PHP 读取 大文件 解决方法
- php读取大文件详解
- PHP读取大excel文件
- php 读取HTML变成XML
- php 读取,分割大文件详解
- PHP快速读取CSV大文件
- PHP读取大文件小技巧
- UVA - 409 Excuses, Excuses!
- 【服务器编程】多线程安全数据库连接池
- UVA - 10878 Decode the tape
- SCU2016-01 P 二分 + 叉积应用
- UVA - 10815 Andy's First Dictionary
- PHP YIELD使读取大文件变成可能
- 创建对象的几种方法
- SpringMVC常用注解,返回方式,路径匹配形式,验证【转】
- 设计模式--模板方法模式
- classpath路径【转】
- 虚幻4 dump 材质编辑器编译出来的 shader的hlsl文件
- CodeForces - 686B
- 【杭电oj】5246 - 超级赛亚ACMer(二分 & 贪心 & STL)
- Android学习第3天,test、sqlite、listview、dialog