I needed this when I have a list of content that are retrieved by javasript that's why google can only index a bit of my content. So I decided to create my own sitemap.

First create the XML

function sitemap_generate()
{
header('Content-Type: application/xml');
echo ''."n";
?>




http://www.website.com/detail//

weekly
0.80






Then Create this page to create sitemap

function sitemap_url()
{
$url = base_url().'scrapper/scrap/sitemap_generate';
$my_file = fopen('sitemap.xml', 'w');

$ch = curl_init($url);
$timeout = 300;

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $my_file);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 4096);
curl_exec($ch) OR die("Error in curl_exec()");

echo("got to after curl exec");

fclose($my_file);
curl_close($ch);
}

This can be useful, you can use cron with this so you just create a cron hit on function sitemap_url