drpsrvu85668 2012-03-23 09:15
浏览 61

我想使用wwwcopy脚本从我的PHP内容创建几个静态html页面

Edited on 7/16/2012

I need to revisit this problem. I have been using dynamic pages for some time with cached PHP on it for some time. Most of my page is cached, but the meta information is not. As i have explained in my post below, i need to reduce/remove requests going to my local MySQL database. I am getting 500 internal server errors because of the requests that are coming. I have been exploring Jquery/Ajax to pull data from the database into a xml page and have the site request data from that, which is working, but i am still running into the problem to move the content from the body, into the meta so facebook, and search engines can see the dynamic content. Here is what i need........

I need a solution that will either create about 1500 static pages by looking at http://chennaichristianradio.com/PHP/web/songinfo.php?songID= and start with 0 and count up to 1500 (http://chennaichristianradio.com/PHP/web/songinfo.php?songID=0 to http://chennaichristianradio.com/PHP/web/songinfo.php?songID=1500). That would work for me but not preferred.

The second option would be to have a PHP cache option that will cache the entire page including the meta data that is created from PHP.

The third option (my preferred option) is to be able to create meta data from either ajax/Jquery created data in the body, or from the xml page itself.

Thank you for revisiting this request. Please read my original posts from earlier this year. here is some of my current code that i am using and links for examples.....

Current PHP used to create the dynamic pages...

 <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(); 
?>

Here is my new scripts to create the 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

?>

And the script in my html to read the extracted content....

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

Some links Dynamically created Page using PHP: http://chennaichristianradio.com/PHP/web/songinfo.php?songID=5351

XML Page that shows the data that i need in my pages: http://bangalorechristianradio.com/PHP/web/aj.php

Page that has been created using JQuery and Ajax: http://bangalorechristianradio.com/PHP/web/player.html

Thanks everyone for your help!! -Bob Swaggerty

Original post Below

I am wanting to create several hundred static html pages using the following script:

<?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");

I create my php page called create.php, which creates 1 file. How do I use this script and create 1200 pages?

My whole purpose to do this is to minimize requests going to my MySQL database, and make my pages come up faster. After creating these pages, I will use another script to point to these files.

(update on 3/24/2012)

Thank you for your responses. Here is what I am trying to accomplish in doing this. Maybe there is a better solution......

look at my page http://chennaichristianradio.com/PHP/web/songinfo.php?songID=5351

My software is dynamically creating this page from the ID 5351 (the song in my database) I am using php to go grab the song info. To make this process a bit more efficient, I hace set up PHP caching. I am caching this now using....

<?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

?>

The PHP Cache is being accomplished using this, but my problem is it only caches the PHP info from this code and below. The reason this is a problem, is because i use PHP in the meta info aslo for my Open Graphic tags. The OG is so people can "like" my music in Facebook. Here is what my OG tags look like.

<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...... What is the solution for caching my dynamic page AND include the meta info. That is defiantly the best option, but with my current code, it still queries my MYSql server for the Meta info and the song info. I thought by creating static pages for this and telling my software to point to these pages instead of querying my database it would be more efficient, as well as help in reducing my PHP traffic back to my server. Hope this clarifies my need, and I thank everyone for their response and help.

  • 写回答

2条回答 默认 最新

  • dongque5529 2012-03-23 10:43
    关注

    I'm not sure what you are trying to achieve but to do this 1200 times simply use a for loop and change the filename and urls.

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测