2012-03-23 6 views
0

編集日2012/07/16wwwcopyスクリプトを使用してPHPコンテンツからいくつかの静的HTMLページを作成したい

この問題を再訪する必要があります。私はしばらくの間、キャッシュされたPHPを使用してしばらくの間、動的ページを使用してきました。私のページのほとんどはキャッシュされていますが、メタ情報はありません。私の下の記事で説明したように、私はローカルMySQLデータベースへのリクエストを減らしたり削除したりする必要があります。私は、来ている要求のために500の内部サーバーエラーを取得しています。私は、JQuery/Ajaxを使ってデータベースからXMLページにデータを取り込み、そこからサイト要求データを取得していますが、これは問題なく動作しています。 Facebook、検索エンジンは動的コンテンツを見ることができます。ここに私が必要なのは.......

http://chennaichristianradio.com/PHP/web/songinfo.php?songID=を見て約1500の静的ページを作成し、0から始まり1500までカウントするソリューションが必要です(http:// chennaichristianradio。 com/PHP/web/songinfo.php?songID = 0〜http://chennaichristianradio.com/PHP/web/songinfo.php?songID=1500)。それは私のために働くだろうが、好まれていない。

第2のオプションは、PHPから作成されたメタデータを含むページ全体をキャッシュするPHPキャッシュオプションを持つことです。

3番目のオプション(私が推奨するオプション)は、ajax/Jqueryで作成したデータを本体またはxmlページ自体から作成することができます。

このリクエストに再度ご回答いただきありがとうございます。今年初めから私の元の記事を読んでください。ここに私の現在の私が使用していたコードとリンクのいくつかは、ここで

<title>Chennai Christian Radio</title> 
    <meta property="og:title" content="<?php echo $song->title; ?> by <?php echo $song->artist; ?> - Found on Chennai Christian Radio"/> 
    <meta property="og:type" content="song"/> 
    <meta property="og:url" content="http://chennaichristianradio.com/PHP/web/songinfo.php?songID=<?php echo $song->ID; ?>"/> 
    <meta property="og:image" content="<?php echo $song->picture; ?>"/> 
    <meta property="og:site_name" content="Chennai Christian Radio"/> 
    <meta property="fb:admins" content="1013572426"/> 
<?php 

     $cachefile = "cache/".$reqfilename.$cache_folder.md5($_SERVER['REQUEST_URI']); 


     $cachetime = 11000 * 60; // 110000 minutes 


     // Serve from the cache if it is younger than $cachetime 

     if (file_exists($cachefile) && (time() - $cachetime 
     < filemtime($cachefile))) 
     { 

     include($cachefile); 


     echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." 
     -->n"; 


     exit; 

     } 

     ob_start(); // start the output buffer 


?> 
<div id="fbbutton"> 
<div id="fb-root"></div> 
<script>(function(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=170819122971839"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 
<div class="fb-like" data-send="false" data-layout="box_count" data-width="50" data-show-faces="false"></div> 
</div> 

<div id="songinfo"> 

<!-- BEGIN:AlbumArt --> 
<?php if(SHOW_PICTURES && !empty($song->picture)) : ?> <img class="picture" id="picture" onload="showPicture(this, <?php echo SHOW_PICTURES; ?>)" src="<?php echo $song->picture; ?>" alt="" border=0 width="142" height="142" /></a><?php endif; ?> 


</div> 
<!-- Song Info --> 
<div id="wrapper"> 
<div id="title"><?php echo $song->title; ?></div> 
<div id="artist"><?php echo $song->artist; ?></div> 
<div id="album"><?php echo $song->album; ?></div> 
<div id="duration"><?php echo $song->durationDisplay; ?></div> 
<div id="year"><?php echo $song->albumyear; ?></div> 
</div> 
<div id="lyrics"><pre><?php if (!empty($song->lyrics)) : ?><dd class="broad"><pre><?php echo $song->lyrics; ?><?php endif; ?></pre></div> 
<?php 
     // open the cache file for writing 
     $fp = fopen($cachefile, 'w'); 


     // save the contents of output buffer to the file 
     fwrite($fp, ob_get_contents()); 

     // close the file 

     fclose($fp); 

     // Send the output to the browser 
     ob_end_flush(); 
?> 

を作成するために、私の新しいスクリプトです...

現在のPHPは、動的なページを作成するために使用される.....例ですXML .......

<?php 

    // Change to your database user name 
    $username="*********"; 


    //Change to your database password 
    $password="*********"; 


    // Change to your database name 
    $database="********"; 

    // Connect to the database 
    mysql_connect('*********',$username,$password); 

    // Handle an error 
    @mysql_select_db($database) or die("Unable to select database"); 

     // Build Sql that returns the data needed - change this as required.  
     $sql = "SELECT songlist.*, historylist.listeners as listeners, historylist.requestID as requestID, historylist.date_played as starttime FROM historylist,songlist WHERE (historylist.songID = songlist.ID) AND (songlist.songtype='S' OR songlist.songtype='C' OR songlist.songtype='N') ORDER BY historylist.date_played DESC LIMIT 1"; 


     // Store results in result object 
     $result = mysql_query($sql); 


     //store values in vars for calculation for array creation 
     $curPlay = mysql_query("SELECT * FROM historylist ORDER BY date_played DESC LIMIT 1"); 
     $curPlayRow = mysql_fetch_assoc($curPlay); 
     if (!$curPlay) { echo(mysql_error()); } 
     $dt_duration = mysql_result($result,$i,'duration'); 
     $title= mysql_result($result,$i,'title'); 
     $artist= mysql_result($result,$i,'artist'); 
     $album= mysql_result($result,$i,'album'); 
     $picture= rawurlencode(mysql_result($result,$i,'picture')); 
     $lyrics= mysql_result($result,$i,'lyrics'); 
     $ID= mysql_result($result,$i,'ID'); 
     $curtime = time(); 
     $timeleft = $starttime+round($dt_duration/1000)-$curtime; 
     $secsRemain = (round($dt_duration/1000)-($curtime-$starttime)); 

     //build array to return via getXMLHTTPRequest object - you can include more vars but remeber to handle them 
     //correcty in the useHttpResponse function  
     $Aj_array = $dt_duration . '|' . $secsRemain . '|' . $title . '|' . $artist .'|' . $album .'|' . $picture .'|' . $lyrics .'|' . $ID; 

     //we are using the text response object - which i think is easier for small data return 
     //just echo the array     - not so much AJAX rather AJA ?? 
     echo $Aj_array 

?> 

そして、抽出されたコンテンツを読むために私のHTML内のスクリプト....

<script language="JavaScript"> 

    var http = getXMLHTTPRequest(); 
    var counter; 

     function getXMLHTTPRequest() { 
     try { 
     req = new XMLHttpRequest(); 
     } catch(err1) { 
     try { 
     req = new ActiveXObject("Msxml2.XMLHTTP"); 
     } catch (err2) { 
      try { 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
      } catch (err3) { 
      req = false; 
      } 
     } 
     } 
     return req; 
     } 



     function getServerText() { 
     var myurl = 'http://bangalorechristianradio.com/PHP/web/aj.php'; 
     myRand = parseInt(Math.random()*999999999999999); 
     var modurl = myurl+"?rand="+myRand; 
     http.open("GET", modurl, true); 
     http.onreadystatechange = useHttpResponse; 
     http.send(null); 
     } 

     function useHttpResponse() { 
       if (http.readyState == 4) { 
      if(http.status == 200) { 
      var aj_results = http.responseText.split("|"); 

      var aj_duration = aj_results[0]; 
      var aj_secsremaining = aj_results[1]; 
      var aj_title = aj_results[2]; 
      var aj_artist = aj_results[3]; 
      var aj_album = aj_results[4]; 
      var aj_picture = aj_results[5]; 
      var aj_lyrics = aj_results[6]; 
      var aj_ID = aj_results[7]; 

      // update title and artist divs 

      document.getElementById('title').innerHTML = aj_title; 
      document.getElementById('artist').innerHTML = aj_artist; 
      document.getElementById('album').innerHTML = aj_album; 
      document.getElementById('picture').innerHTML = "<img src=http://chennaichristianradio.com/images/album_art/" + aj_results[5] +" width='142' height='142'>" 
      document.getElementById('lyrics').innerHTML = aj_lyrics; 

      countDownInterval = aj_secsremaining - 0; 
      countDownTime = countDownInterval + 1; 
      countDown() 
      } 
     } else { 
     //document. getElementById('actual').innerHTML = ""; 
     } 
     } 




    function countDown() { 
     countDownTime--; 
     if (countDownTime == 0) { 
     countDownTime = countDownInterval; 
     getServerText() 
     } 
     else if (countDownTime < 0) 
     countDownTime = 30; 
     if (document.all) 
     document.all.countDownText.innerText = secsToMins(countDownTime); 
     else if (document.getElementById) 
     document.getElementById("countDownText").innerHTML = secsToMins(countDownTime); 
     stopCountDown(); 
     counter = setTimeout("countDown()", 1000); 
    } 

    function secsToMins(theValue) { 
     var theMin = Math.floor(theValue/60); 
     var theSec = (theValue % 60); 
     if (theSec < 10) 
     theSec = "0" + theSec; 
     return(theMin + ":" + theSec); 
    } 

    function stopCountDown() 
     { 
     clearTimeout(counter) 
     } 

</script> 

いくつかのリンク私は私のページに必要なデータを示してhttp://chennaichristianradio.com/PHP/web/songinfo.php?songID=5351

XMLのページ:jQueryとAjaxのを使用して作成されていhttp://bangalorechristianradio.com/PHP/web/aj.php

ページ:あなたのためのhttp://bangalorechristianradio.com/PHP/web/player.html

みんなありがとうをS 動的にPHPを使用してページを作成しました助けて!!

<?php 
function wwwcopy($link,$file) 
{ 
    $fp = @fopen($link,"r"); 
    while(!feof($fp)) 
    { 
     $cont.= fread($fp,1024); 
    } 
    fclose($fp); 

    $fp2 = @fopen($file,"w"); 
    fwrite($fp2,$cont); 
    fclose($fp2); 
} 

wwwcopy("http://www.domain.com/list.php?member=sample", "sample.html"); 

私は1を作成create.phpと呼ばれる私のPHPページを作成します。私は次のスクリプトを使用して、数百の静的なHTMLページを作成したいのです -Bob Swaggerty

以下はオリジナルのポストファイル。このスクリプトを使用して1200ページを作成するにはどうすればよいですか?

これを行う私の全目的は、MySQLデータベースへのリクエストを最小限に抑え、ページを高速化することです。これらのページを作成した後、私はこれらのファイルを指す別のスクリプトを使用します。

(2012年3月24日に更新)

ご回答いただきありがとうございます。ここでこれを達成するために私が達成しようとしていることがあります。よりよい解決策は、私のページで

http://chennaichristianradio.com/PHP/web/songinfo.php?songID=5351

私のソフトウェアを動的に私が行くためにPHPを使用していますID 5351(私のデータベース内の曲) からこのページを作成しています......たぶんあり曲情報をつかむ。このプロセスをより効率的にするために、私はPHPキャッシュを設定します。私は....使用して、今

<?php 

    $cachefile = "cache/".$reqfilename.$cache_folder.md5($_SERVER['REQUEST_URI']); 


    $cachetime = 11000 * 60; // 110000 minutes 


    // Serve from the cache if it is younger than $cachetime 

    if (file_exists($cachefile) && (time() - $cachetime 
    < filemtime($cachefile))) 
    { 

    include($cachefile); 


    echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." 
    -->n"; 


    exit; 

    } 

    ob_start(); // start the output buffer 

これをキャッシュするのですか?>

PHPキャッシュがこれを使用して達成されているが、私の問題はそれだけで、このコードと下からPHP情報をキャッシュしています。これが問題である理由は、私がOpen Graphicタグのメタ情報asloをPHPで使用しているからです。 OGは人々がFacebookの私の音楽を「好き」できるようにするものです。ここに私のOGタグの様子があります。

<title>Chennai Christian Radio</title> 
<meta property="og:title" content="<?php echo $song->title; ?> by <?php echo $song->artist; ?> - Found on Chennai Christian Radio"/> 
<meta property="og:type" content="song"/> 
<meta property="og:url" content="http://chennaichristianradio.com/PHP/web/songinfo.php?songID=<?php echo $song->ID; ?>"/> 
<meta property="og:image" content="<?php echo $song->picture; ?>"/> 
<meta property="og:site_name" content="Chennai Christian Radio"/> 
<meta property="fb:admins" content="1013572426"/> 
<meta property="og:description" 
     content="Chennai Christian Radio is your last stop for today's best Christian Music. http://chennaichristianradio.com"/> 

So ......私のダイナミックページをキャッシュし、メタ情報を含む解決策は何ですか?それは挑戦的に最良の選択ですが、私の現在のコードでは、依然としてMYSqlサーバーにメタ情報と曲情報を問い合わせます。私はこのための静的なページを作成し、私のデータベースを照会するのではなく、より効率的なこれらのページを指すように私のソフトウェアを指摘し、私のサーバーに私のPHPトラフィックを減らすのに役立つと思った。これが私の必要性を明確にしてくれることを願っています。

答えて

0

私はあなたが達成しようとしていることは分かっていませんが、これを行うには1200回、単にforループを使用してファイル名とURLを変更してください。

for ($i = 1; $i <= 1200; $i++) 
{ 
    wwwcopy("url", "file"); 
} 
+0

私が達成しようとしていることを理解するために私のアップデートを参照してください。ありがとうございました。 –

0

キャッシュオプションにする必要があると思います。フレームワークを使用している場合、キャッシュを有効にするためのデフォルト設定があります。これは本当にあなたのスピードを向上させます。

関連する問題