2010-11-23 15 views
0

をセルフホスティング私は会社が私に次のような制限を持つXMLファイルを提供させるような状況があります。フェッチ&XMLフィード

  1. ユーザー名/パスワード
  2. を保護し、そのFTP
  3. に保存されているI 「Mだから私は(そのファイルは時間ごとに更新される)xmlファイルごとに時間を取得するために何かを思い付くことを期待して、そして私自身のドメインにホストされた

自分のアプリケーションからファイルを参照することはできません。

誰かがこのようなものを作成することに関する提案はありますか、それとも私のためにそれを行う可能性のある既存のスクリプトはありますか?

多くのおかげで、 グレン

+1

どの言語(PHP、.NETのC#の、など)/? ...ファイルの大きさはどれくらいですか? –

+0

私は、.NET対応のWindowsサーバーを使用していると思いますが、PHPも有効です。私はそれを読むことができるようにおそらくPHPを好む:)ファイルは小さいです - 5kbの下 – Nelga

+0

ちょうど私の答えが助けたのですか? –

答えて

1

あなたは、リモートファイルをキャッシュし、ローカルコピーを提供するためにPHPの単純なビットを使用することができます。あなたが(未テスト)このような何かを行うことができ、このPHP Remote File Cache例に基づいて

<?php 
$url = 'ftp://username:[email protected]/folder/file.ext'; 
#we need to do some caching here 
$cache_dir = dirname(__FILE__) . '/cache/'; // directory to store the cache 
$cache_file = $cache_dir . md5($url); 
$cache_time = 1 * 60 * 60; // time to cache file, # minutes * seconds 

// check the cache_dir variable 
if (is_dir($cache_dir) && 
    is_writable($cache_dir) && 
    file_exists($cache_file) && 
    (time() - $cache_time) < filemtime($cache_file)) { 
    $data = file_get_contents($cache_file); // name of the cached file 
} 
else { 
    $data = file_get_contents($url); 
    file_put_contents($cache_file, $data); //go ahead and cache the file 
} 


// Compress output if we can. 
if (function_exists('ob_gzhandler')) { 
    ob_start('ob_gzhandler'); 
} 


header('Content-type: text/xml; charset=UTF-8'); // Change this as needed 
// think about client side caching... 
header('Cache-Control: must-revalidate'); 
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cache_time) . ' GMT'); 
echo $data; 
exit; 
関連する問題