search
HomePHP LibrariesOther librariesPHP class that generates Baidu sitemap sitemap
PHP class that generates Baidu sitemap sitemap
<?php
/*
 * SiteMap接口类
 */
class SitemapAction extends Action{
  private static $baseURL = ''; //URL地址
  private static $askMobileUrl = 'http://m.xxx.cn/ask/'; //问答移动版地址
  private static $askPcUrl = "http://www.xxx.cn/ask/";   //问答pc地址
  private static $askZonePcUrl = "http://www.xxx.cn/ask/jingxuan/"; //问答精选Pc链接
  private static $askZoneMobileUrl = "http://m.xxx.cn/ask/jx/"; //问答精选移动版链接
  //问答setmaps
  public function askSetMap(){
    header('Content-type:text/html;charset=utf-8');
    //获取问题列表
    $maxid = 0;    //索引文件最大id
    $minid = 0;    //索引文件最小id
    $psize = 1000; //数据库每次取数量
    $maxXml = 5000; //xml写入记录数量
    $where = array();
    //读取索引文件
    $index = APP_PATH.'setmapxml/Index.txt';
    //关联setmaps路径
    $askXml = "../siteditu/ask/ask.xml";
    if(!file_exists($index)){
      $fp=fopen("$index", "w+");
      if ( !is_writable($index) ){
        die("文件:" .$index. "不可写,请检查!");
      }

First take out 1000 pieces of data (which can be more flexible and convenient for later modification), and then generate xml format files in a loop. file_puts_contens writes files. Then write the name of the generated xml file, the minimum id of the retrieved question, the maximum id of the retrieved question, and the number of retrieved questions into a txt file for index query. The format is roughly like this.
0,3146886,3145887,1000
Did you find that the last number is 1000? The first time you select, take out 1000 pieces of data, and then write it into the 0.xml file. Write the extracted xml file name, minimum id, maximum id, and number of entries into the index query txt. For the first time, 1,000 pieces of data were written to 0.xml, and the number of pieces generated was 1,000. The select statement will become when querying for the second time. where id > The maximum id taken out (currently mysql is a forward order query, if it is in reverse order, change it to less than) limit 1000 In this case, take out 1000, and then modify the minimum id and maximum id of the index query txt, and add the number of generated items to 2000 . By analogy, when the number of generated items reaches 5000, start another line and write it into the index file, similar to this
0,3146886,3145887,5000
1,3148886,3147887,1000
If you write it like this, it will reduce the problem. reduces the pressure on the server.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

How Do I Link Static Libraries That Depend on Other Static Libraries?How Do I Link Static Libraries That Depend on Other Static Libraries?

13Dec2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

How to Silence TensorFlow\'s Debugging Output?How to Silence TensorFlow\'s Debugging Output?

28Oct2024

Suppression of Tensorflow Debugging OutputTensorflow prints extensive information about loaded libraries, found devices, and other debugging data...

How Does jQuery Simplify DOM Manipulation for Web Developers?How Does jQuery Simplify DOM Manipulation for Web Developers?

03Jan2025

Overflow: Hidden and Expansion of HeightjQuery distinguishes itself from other JavaScript libraries through its cross-platform compatibility and...

Which native Java image processing library is right for you?Which native Java image processing library is right for you?

30Oct2024

Native Java Image Processing Libraries for High-Quality ResultsAs you have encountered limitations with ImageMagick and JAI, let's explore other...

How to Execute Command Line Binaries in Node.js?How to Execute Command Line Binaries in Node.js?

27Dec2024

Executing Command Line Binaries in Node.jsExecuting third-party binaries is an essential task when porting CLI libraries from other languages to...

How to Create and Utilize Static Libraries in g  ?How to Create and Utilize Static Libraries in g ?

24Oct2024

This article guides developers on crafting static libraries in C using g . It demonstrates how to compile source code into object files, create static libraries, and incorporate them into other projects. By leveraging this approach, developers can

See all articles