Icecat&;PHP files.index.xml

Icecat&;PHP files.index.xml,php,xml,e-commerce,Php,Xml,E Commerce,我运行了几个脚本,下载每日xml并查找其中的每个.xml,然后将它们下载到不同的文件夹中,以便 1234.xml / daily.index.xml - - 4567.xml \ 6789.xml 现在,我希望对files.index.xml文件执行相同的操作,但每次尝试打开索引文件时,服务器都会停止: PHP致命错误:允许的10737418

我运行了几个脚本,下载每日xml并查找其中的每个.xml,然后将它们下载到不同的文件夹中,以便

                    1234.xml
                  / 
daily.index.xml - - 4567.xml
                  \
                    6789.xml
现在,我希望对files.index.xml文件执行相同的操作,但每次尝试打开索引文件时,服务器都会停止:

PHP致命错误:允许的1073741824字节内存已耗尽 (尝试分配1073217536字节)

有没有一种方法可以打开并解析files.index.xml,而不会让我的服务器不断崩溃

更新: 我相信服务器在运行脚本时挂起了,因为一些XML文件存储在目录中

脚本:

// URL for index file
$url = "http://data.icecat.biz/export/level4/EN/files.index.xml";


// Custom header (username/pass is a paid account, so I can't share the credentials)
$context = stream_context_create(array (
    'http' => array (
        'header' => 'Authorization: Basic ' . base64_encode("username:pass")
    )
));

// Get XML File
$indexfile = file_get_contents($url, false, $context);


// Save XML
$file = '../myhomeservices/fullindex/files_index.xml';
unlink($file); 
$dailyfile = fopen("../myhomeservices/fullindex/files_index.xml", "w") or die("Unable to open file!");
chmod($dailyfile, 0777); 
// Write the contents back to the file
$dailyxmlfile = fwrite($dailyfile, $indexfile);
if($dailyxmlfile){
} else {
echo 'Error!';  
}
fclose($myfile);enter code here
Apache记录“文件获取内容($url,false,$context);”导致内存最大化


目前,我正试图上传files.index.xml(1,41gb文件),希望能以这种方式处理它。

根据提供的信息,这里有两个问题。最直接的问题是,在PHP脚本已经达到1GB限制(比默认限制高得多)之后,您试图为其分配额外的1GB内存。假设您使用的是PHP 5.1+,则可以使用
fopen()
file\u put\u contents()
在HTTP和磁盘之间缓冲文件:

<?php
$url = "http://data.icecat.biz/export/level4/EN/files.index.xml";

// Custom header (username/pass is a paid account, so I can't share the credentials)
$context = stream_context_create(array (
    'http' => array (
        'header' => 'Authorization: Basic ' . base64_encode("username:pass")
    )
));

$file = '../myhomeservices/fullindex/files_index.xml';
@unlink($file); 
chmod($file, 0777); 

// Write the contents back to the file
if (!file_put_contents($file, fopen($url, 'r', false, $context)))
{
    echo 'Error!';  
}

您需要显示导致错误的代码您可以发布访问和解析XML文件的代码吗?代码试图在您已经允许它使用的1GB内存之上分配1GB内存。还有什么是Icecat?这应该是Icecast,流媒体工具吗?@基于xml,我想不要把整个文件读到内存中,用Chunkstory做,我的意思是
fopen()
,而不是
file\u get\u contents()
。但是是的,
fopen()
/
fread()
可以正常工作,但是您必须担心如何正确处理边缘情况
fgets()
逐行读取,而“块”在这里更合适。