简体   繁体   中英

How to open a file on a distant server with XML Reader in php?

I have got a huge xml file (~ 85 Mo) and I would like to open it with XML Reader (then my script read selected lines). I have downloaded it on my PC and my script works (using Wamp).

Now I would like to do the same online. Server login is aaa and password is bbb (of course it's an example).

I tried the following statement:

$xml = new XMLReader();
if ($xml->open('ftp://aaa:bbb@ftp.website.com/myfile.xml')){
    echo 'OK';
}

while($xml->read()){
    // my script here... 
}

It seems I am wrong because my web browser indicates me that the page is too long to load. What is the good way to proceed? Or did I miss something important?

Since the file in question is an XML it is not wise to partially download it since it will probably break the xml structure making the parser to fail.

You could get a cronjob to retrieve the file occasionally and you would open it from a local location on the server, or retrieve it once and cache it locally so that it would speed subsequent requests.

http://davidwalsh.name/increase-php-script-execution-time-limit-ini_set默认执行时间为20秒或30,将其增加到1分钟并重试

I would use curl to connect to the FTP server and download the file.

http://php.net/manual/en/book.curl.php

Your probably best to download the file to the server first using PHP's FTP functions and then open the file locally. I wouldn't rely on using FTP within the XML library, you'll get more flexibility this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM