Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文件太大,我无法';我无法获取php程序的输入_Php_File_File Io - Fatal编程技术网

文件太大,我无法';我无法获取php程序的输入

文件太大,我无法';我无法获取php程序的输入,php,file,file-io,Php,File,File Io,我想从txt文件中获取输入,但该文件包含1.6GB的数据。因此,当我将数据加载到我的变量中时,它崩溃了。如何在php程序中获取数据 $handle = fopen("file.txt", "r") or die("Couldn't get handle"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); // Process here.. }

我想从txt文件中获取输入,但该文件包含1.6GB的数据。因此,当我将数据加载到我的变量中时,它崩溃了。如何在php程序中获取数据

$handle = fopen("file.txt", "r") or die("Couldn't get handle");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        // Process here..
    }
    fclose($handle);
}

所以从文件中加载一行,处理它,读取下一行,处理它,读取下一行,等等。。。。不要试图一次加载所有文件为什么要用PHP处理这个文件?是的,你实际上并不是想在网页上显示1.6GB的数据,对吧?对吧?他没说他用它做网页。这些1.6GB的数据可以放在一行中。人们使用php编写脚本too@Jack-我用PHP做了很多非web的事情,而且它也完全能够做到这一点-这就是工作!!但我做了一个twitter应用程序,它的错误显示“错误太多请求”我怎么能管理它呢!!谢谢
$file = fopen($filename);
while ($line = fgets($file)) {
    // do stuff
}
fclose($file);