PHP从txt文件读取大量数据的问题

PHP从txt文件读取大量数据的问题,php,readfile,Php,Readfile,我正在运行一个php脚本,它读取一些管道分隔的txt文件,这些文件包含大约22000条记录。我正在使用PHP file()函数读取这些文件,顺便说一句,这些文件也有一些相互关系,为了更好地理解,我将代码粘贴在这里 public function getGames() { $resource = self::DATAFILES.'Product.txt'; $games = array_slice($this->readFile($resource), 1); $

我正在运行一个php脚本,它读取一些管道分隔的txt文件,这些文件包含大约22000条记录。我正在使用PHP file()函数读取这些文件,顺便说一句,这些文件也有一些相互关系,为了更好地理解,我将代码粘贴在这里

public function getGames()
{
    $resource = self::DATAFILES.'Product.txt';

    $games = array_slice($this->readFile($resource), 1); 
    $data = array();
    $count = 1;
    foreach($games as &$records)
    {
        $game = new Game();
        $attributes = explode($this->delimiter,$records);
        $game->api   =  (int) $attributes[0];
        $game->console_id = (string) $attributes[1];
        $game->title = (string) $this->getTitle($attributes[2]);
        $game->barcode = (string) $attributes[4];
        $game->image = $this->getCoverImage($attributes[0]);
        $game->releateDate = strtotime($attributes[8]);
        $data[] = $game;
        //if($count == 100): break; else: $count++; endif;
    }

    print '<pre>'; print_r($data); 


}

public function getTitle($titleID)
{
    $resource = self::DATAFILES.'Title.txt';

    $titles = array_slice($this->readFile($resource), 1); 

    foreach($titles as $records)
    {
        $attributes = explode($this->delimiter,$records);

        $pattern = '/^' . preg_quote($attributes[0], '/') . '$/';
        if (preg_match($pattern, $titleID))
        {
            return $attributes[2];
            break;
        }

    }

}

public function getCoverImage($gameID)
{
    $resource1 = self::DATAFILES.'ProductImage.txt';

    $coverImages = array_slice($this->readFile($resource1), 1); 

    foreach($coverImages as $img_records)
    {
        $image_attributes = explode($this->delimiter,$img_records);

        $pattern1 = '/^' . preg_quote($image_attributes[0], '/') . '$/';
        $pattern2 = '/^' . preg_quote($image_attributes[3], '/') . '$/';

        if (preg_match($pattern1, $gameID) && preg_match($pattern2, 'Cover'))
        {
            return $image_attributes[2];
            break;
        }

    }
公共函数getGames()
{
$resource=self::DATAFILES.Product.txt';
$games=array\u slice($this->readFile($resource),1);
$data=array();
$count=1;
foreach($games as&$records)
{
$game=新游戏();
$attributes=explode($this->delimiter,$records);
$game->api=(int)$attributes[0];
$game->console_id=(字符串)$attributes[1];
$game->title=(字符串)$this->getTitle($attributes[2]);
$game->barcode=(字符串)$attributes[4];
$game->image=$this->getCoverImage($attributes[0]);
$game->relatedate=strottime($attributes[8]);
$data[]=$game;
//if($count==100):中断;else:$count++;endif;
}
打印“”;打印($data);
}
公共函数getTitle($titleID)
{
$resource=self::DATAFILES'Title.txt';
$titles=array\u slice($this->readFile($resource),1);
foreach($记录的标题)
{
$attributes=explode($this->delimiter,$records);
$pattern='/^'。preg_quote($attributes[0],'/')。$/';
if(预匹配($pattern$titleID))
{
返回$attributes[2];
打破
}
}
}
公共函数getCoverImage($gameID)
{
$resource1=self::DATAFILES.ProductImage.txt';
$coverImages=array\u slice($this->readFile($resource1),1);
foreach($coverImages作为$img_记录)
{
$image\u attributes=explode($this->delimiter,$img\u records);
$pattern1='/^'。preg_quote($image_属性[0],'/')。$/';
$pattern2='/^'。preg_quote($image_attributes[3],'/')。$/';
if(预匹配($pattern1,$gameID)和预匹配($pattern2,'Cover'))
{
返回$image_属性[2];
打破
}
}
因此,我在这里面临的问题是——当我运行该脚本时,它将继续运行,并且不会发生任何事情,即不会抛出任何错误,也不会打印返回的数组,但是当我将循环迭代次数限制为100次时,它可以工作,这意味着代码没有问题,所以我想可能是php脚本执行时间造成了问题,所以我更改了它最大执行时间为0-但仍然没有得到结果。任何帮助或建议,都希望听到……)


顺便说一句,我正在为我的本地开发人员使用Xampp Apache!

您让脚本运行多久了?我会在foreach中放入某种打印或回显语句,将当前游戏的标题打印到$data中。这样,您就可以真正看到脚本是否正在停止执行或只是花费了很长时间。感谢您的回复,好吧,我可以让脚本运行半个小时,但它没有输出结果,只是一直加载,而且我已经将内存限制更改为-1,最大输入时间更改为-1,最大执行时间更改为0,但没有任何效果。。