Home PHP Libraries Other libraries PHP 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

PHP generates Baidu sitemap sitemap class function instance, sitemap sitemap_PHP tutorial PHP generates Baidu sitemap sitemap class function instance, sitemap sitemap_PHP tutorial

13 Jul 2016

PHP generates Baidu sitemap sitemap class function instances, sitemap sitemap. PHP generates Baidu sitemap sitemap class function example, sitemap sitemap This article describes the method of PHP generating Baidu sitemap sitemap class function, and shares it with you for your reference. Tool

PHP generates Baidu sitemap sitemap class function instance_PHP tutorial PHP generates Baidu sitemap sitemap class function instance_PHP tutorial

13 Jul 2016

PHP generates Baidu sitemap sitemap class function instances. PHP generates Baidu sitemap site map class function example Problem overview: The company website is a Q&A Encyclopedia website, and the SEO engineer made a request to generate xml files based on the questions on the website. each

php automatically generates sitemap php automatically generates sitemap

15 Oct 2019

The sitemap of the website is the main place for crawlers to crawl. If you submit the URL of the sitemap, crawlers will crawl it first. Therefore, we must have the habit of regularly updating sitemaps. There are many ways to generate sitemaps. Third-party tools can capture and generate them, and you can generate them yourself. Here I recommend generating the sitemap yourself.

PHP example of a class that generates random strings and verification codes_PHP tutorial PHP example of a class that generates random strings and verification codes_PHP tutorial

13 Jul 2016

PHP instance of a class that generates random strings and verification codes. There are a lot of PHP random number and verification code codes and articles on the Internet, but few are really applicable. Just make one yourself. Let’s start this php tutorial. The implementation of the following code is mainly

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

13 Dec 2024

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

How to import third-party libraries in ThinkPHP How to import third-party libraries in ThinkPHP

03 Jun 2023

Third-party class libraries Third-party class libraries refer to other class libraries besides the ThinkPHP framework and application project class libraries. They are generally provided by third-party systems or products, such as class libraries of Smarty, Zend and other systems. For the class libraries imported earlier using automatic loading or the import method, the ThinkPHP convention is to use .class.php as the suffix. Non-such suffixes need to be controlled through the import parameters. But for the third type of library, since there is no such agreement, its suffix can only be considered to be php. In order to easily introduce class libraries from other frameworks and systems, ThinkPHP specifically provides the function of importing third-party class libraries. Third-party class libraries are uniformly placed in the ThinkPHP system directory/

See all articles