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

时间:2013-11-17 17:26:50

标签: php readfile

我正在运行一个从一些管道分隔的txt文件中读取的php脚本,这些文件包含大约22,000条记录。我正在使用PHP file()函数来读取这些文件,BTW文件也有一些相互关系,我在这里粘贴代码以便更好地理解

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;
        }

    }

所以我在这里面临的问题是 - 当我运行该脚本时,它将继续发生任何事情,即从不抛出任何错误既不打印返回的数组,但是当我限制循环迭代达到100时工作,这意味着代码没有错,所以我想也许,PHP脚本执行时间制造麻烦所以我把它改为max_execution_time = 0 - 但仍然没有得到结果。任何帮助或建议,都会喜欢听到...... :)

BTW我正在使用Xampp Apache为我的本地开发人员!

0 个答案:

没有答案