basically i have a script processing a lot of data from a lot of tables. And its stopping before its finished and im trying to find out why. So im wondering if a case such as
do
{
$DBConnect = mysqli_connect("localhost", "username", "xxxxxxx!");
mysqli_set_charset($DBConnect, "utf8");
mysqli_select_db($DBConnect, "dbname");
$qwry = "select something from `something`;"; // start writting all the eng pages/
$QueryResult = mysqli_query($DBConnect, $qwry);
$Row = mysqli_fetch_row($QueryResult);
do
{
//.....(Doing something for a long time)...
if(mysqli_ping($DBConnect)) $Row = mysqli_fetch_row($QueryResult);
}while(something);
}while(somethingelse);
the (doing something) in the loop does not take a long time. but the loop has to do many tens of thousands of loops before its finished.
does the row fetching require the db connection to be open? if it does could the db connection time out if the inner loop takes too long to finish?
I would have thought that calling mysqli_fetch_rows would reset the inactive timer to 0. does it?
here is the real script in question:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<?php
set_time_limit(0);
ignore_user_abort(true);
include "functions.php";
$maxfiles = 1000;
$max = 10000;//49990;
$limit = "";//"limit 500";
$date = date("y-m-d"); // 03.10.01
$date = "20".$date;
echo "date [$date]";
$start = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'."\n".'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n".'
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9'."\n".'
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."\n";
$stringData = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'."\n".'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n".'
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9'."\n".'
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."\n".'
<url>'."\n";
$DBConnect = mysqli_connect("localhost", "user", "xxxxx!");
mysqli_set_charset($DBConnect, "utf8");
mysqli_select_db($DBConnect, "db");
$qwry = "select ISO3 from `languages`;"; // start writting all the eng pages/
$QueryResult = mysqli_query($DBConnect, $qwry);
$Row = mysqli_fetch_row($QueryResult);
$count = 0;
do
{
if($Row[0] == 'yue') //just a language i want to skip from processing
{
$count--;
}
else $languages[$count] = $Row[0];
$Row = mysqli_fetch_row($QueryResult);
$count++;
}while($Row);
mysqli_close($DBConnect);
$lcount = 0;
ob_start();
do // language loop
{
$FileName = "sitemaps/".$languages[$lcount]."sitemap.xml";
$fh = fopen($FileName, 'w');// or die("can't open file"); // first erase the old sitemap
$stringData = "";
fwrite($fh, $stringData);
//echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());
//exit();
$fh = fopen($FileName, 'a');// or die("can't open file"); // now make the new one
fwrite($fh, $stringData);
$DBConnect = mysqli_connect("localhost", "mrhowtos_user", "9Xhe9e949Xhe9e94!");
mysqli_set_charset($DBConnect, "utf8");
mysqli_select_db($DBConnect, "mrhowtos_main");
$qwry = "select id, language from `sentences` order by id ASC $limit;"; // start writting all the eng pages/
$QueryResult = mysqli_query($DBConnect, $qwry);
$Row = mysqli_fetch_row($QueryResult);
$filecount = 0;
$count = 1;
$tcount = 0;
do // file loop
{ $skipcount = 0;
do// sentence loop
{
if(($Row[1] != 'yue') and ($Row[1] != $languages[$lcount]) and (hastranslationsin($Row[0], $languages[$lcount])) ) //if languages dont match, and a translation in the desired lang was found
{
$stringData = ' <url>'."\n".'
<loc>http://www.mrhowtosay.com/view?id='.$Row[0].'&lang='.$languages[$lcount].'</loc>'."\n".'
<lastmod>'.$date.'T14:22:08+00:00</lastmod>'."\n".'
<priority>0.80</priority>'."\n".'
<changefreq>monthly</changefreq>'."\n".'
</url>'."\n";
fwrite($fh, $stringData);
echo 'http://www.mrhowtosay.com/view?id='.$Row[0].'&lang='.$languages[$lcount].'<br />';
$count++;
$tcount++;
}
ob_flush();
flush();
$Row = mysqli_fetch_row($QueryResult);
}while(($Row) and ($count < $max));
$stringData = '</urlset>'; //
fwrite($fh, $stringData); // print last line of the file
fclose($fh);
echo "1 sitemap Finished!".$count." URLs inserted into the sitemap $FileName in main dir<br />";
if($Row) // prepare next file for writting,
{
$count = 0; // reset the to 50,000 counter for next file
$FileName = "sitemaps/".$languages[$lcount]."sitemap".$filecount.".xml";//define new file name
//make the new file
$newfile = fopen("./$FileName", "w");
fclose($newfile);
$fh = fopen($FileName, 'w') ;//or die("can't open file"); // first erase the old sitemap
$stringData = "";//make the starting declaration of the sitemap
fwrite($fh, $stringData); //
$fh = fopen($FileName, 'a') ;//or die("can't open file"); // now make the new one
fwrite($fh, $start);
$filecount++;
}
}while(($Row) and($filecount < $maxfiles));
$filestotal = ($filecount+1);
$filecount++;
$filestotal = $filestotal + $filecount;
echo "finished language [".$languages[$lcount]."] $filestotal sitemaps created, and total of $tcount urls<br />";
if ($DBConnect) mysqli_close($DBConnect);
$lcount++;
}while($languages[$lcount]);
echo "finished all sitesmaps for all ".($lcount)." languages<br />";
?>
</body>
</html>