I think everyone has the problem to make a sitemap if you have more than 1M videos …this script counts the packets (40k) in line 19 and then make the packets to generate a sitemap.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#!/usr/bin/perl use strict; use warnings; use DBI; # MYSQL CONFIG VARIABLES my $host = "127.0.0.1"; my $database = "db"; my $tablename = "table"; my $user = "root"; my $pw = "pwd1234"; my $dbh = DBI->connect('DBI:mysql:'.$database , $user, $pw ) || die "Could not connect to database: $DBI::errstr"; my $sitemap_counter = 0; my $th = $dbh->prepare('SELECT round(count(*)/40000+0.5) FROM `video` WHERE `bw` <=80'); $th->execute(); while (my @row = $th->fetchrow_array()) { $sitemap_counter = $row[0]; } for my $SMP (0..$sitemap_counter){ print "build midd".$SMP.".xml ...".$/; open (DATEI, "> /var/www/MAP/midd".$SMP.".xml") or die $!; print DATEI '<?xml version="1.0" encoding="UTF-8"?>'.$/; print DATEI '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'.$/; $th = $dbh->prepare('SELECT CONCAT( "<url><loc>http://www.example.com/view.php?ID=", `id` , "</loc><priority>0.8</priority></url>" ) FROM `video` WHERE `bw` <=80 ORDER BY `id` LIMIT '.(40000*$SMP).' , 40000;'); $th->execute(); while (my @row = $th->fetchrow_array()) { print DATEI $row[0].$/; } print DATEI '</urlset>'; close (DATEI); print "[DONE]".$/; } $dbh->disconnect; exit; |