简体   繁体   English

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

[英]I want to create several static html pages from my PHP content using a wwwcopy script

Edited on 7/16/2012 于2012年7月16日编辑

I need to revisit this problem. 我需要重新考虑这个问题。 I have been using dynamic pages for some time with cached PHP on it for some time. 我使用动态页面已有一段时间,并在上面使用了缓存的PHP。 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. 正如我在下面的帖子中所解释的,我需要减少/删除对本地MySQL数据库的请求。 I am getting 500 internal server errors because of the requests that are coming. 由于即将到来的请求,我收到500个内部服务器错误。 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. 我一直在探索Jquery / Ajax,将数据从数据库中提取到xml页面中,并从该站点请求数据,这是可行的,但是我仍然遇到将内容从主体移到meta的问题。 Facebook,搜索引擎可以看到动态内容。 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 ). 我需要一种解决方案,该解决方案可以通过查看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 )。 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. 第二个选项是使用PHP缓存选项,该选项将缓存整个页面,包括从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. 第三个选项(我的首选)是能够从主体中的ajax / Jquery创建的数据或xml页面本身创建元数据。

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... 当前用于创建动态页面的PHP ...

 <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....... 这是我用于创建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.... 以及我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>

Some links Dynamically created Page using PHP: http://chennaichristianradio.com/PHP/web/songinfo.php?songID=5351 一些使用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 XML页面显示我的页面中需要的数据: http : //bangalorechristianradio.com/PHP/web/aj.php

Page that has been created using JQuery and Ajax: http://bangalorechristianradio.com/PHP/web/player.html 使用JQuery和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: 我想使用以下脚本创建数百个静态html页面:

<?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. 我创建了一个名为create.php的php页面,该页面创建了1个文件。 How do I use this script and create 1200 pages? 如何使用此脚本并创建1200页?

My whole purpose to do this is to minimize requests going to my MySQL database, and make my pages come up faster. 我这样做的全部目的是最大程度地减少对MySQL数据库的请求,并使我的页面显示得更快。 After creating these pages, I will use another script to point to these files. 创建这些页面之后,我将使用另一个脚本来指向这些文件。

(update on 3/24/2012) (2012年3月24日更新)

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 看看我的页面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. 我的软件正在根据ID 5351(数据库中的歌曲)动态创建此页面,我正在使用php来获取歌曲信息。 To make this process a bit more efficient, I hace set up PHP caching. 为了使此过程更有效率,我设置了PHP缓存。 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. 使用此功能可以完成PHP缓存,但是我的问题是它仅缓存此代码及以下代码中的PHP信息。 The reason this is a problem, is because i use PHP in the meta info aslo for my Open Graphic tags. 这是一个问题,是因为我在“开放图形”标签的元信息aslo中使用了PHP。 The OG is so people can "like" my music in Facebook. OG使人们可以“喜欢” Facebook中的音乐。 Here is what my OG tags look like. 这是我的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...... 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. 这绝对是最好的选择,但是使用我当前的代码,它仍然向MYSql服务器查询元信息和歌曲信息。 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. 我认为通过为此创建静态页面并告诉我的软件指向这些页面,而不是查询我的数据库,这将更加有效,同时还有助于减少PHP返回服务器的流量。 Hope this clarifies my need, and I thank everyone for their response and help. 希望这可以澄清我的需求,并感谢大家的回应和帮助。

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. 我不确定您要实现的目标,但是要执行1200次,只需使用for循环并更改文件名和网址即可。

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

I think that you must go for cache option. 我认为您必须选择缓存选项。 If you are using any frame work there are default settings for enabling cache. 如果使用任何框架,则有用于启用缓存的默认设置。 This will really improve your speed. 这确实可以提高您的速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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