SourceTable." as link LEFT JOIN $ValTable as val ON (link.LinkId=val.LinkId) WHERE link.LinkId IS NOT NULL ";
// $sql = "SELECT link.LinkId as LinkId, val.LinkValidationId as LinkValidationId, link.Url as LinkUrl FROM ".$objLinkList->SourceTable." as link LEFT JOIN $ValTable as val ON (link.LinkId=val.LinkId) WHERE link.LinkId IS NOT NULL AND (val.ValidationStatus=2) ";
$SelectedLinks = $_POST['itemlist'];
//print_r($ids = join(",", $SelectedLinks)); die();
// $ids = "";
// $SelectedLinks = explode(",", $ids);
//$SelectedLinks = array('250', '250');
// Get All Counters & Build Full Query
if (($ValidationType != "Full") && ((count($SelectedLinks) && isset($SelectedLinks)) || ($ValidationType == "Temp")))
{
if (count($SelectedLinks))
{
$linkIDs_array = $SelectedLinks;
$linkIDs = implode(",", $SelectedLinks); // string
$add_IDs = count($linkIDs)? " AND link.LinkId IN ($linkIDs)" : "";
$NumLinks = QueryCount($sql.$add_IDs);
$objSession->SetVariable("TotalVal", $NumLinks);
$LinkIndex = 0;
}
else
{
$linkIDs = $objConfig->Get("LinkValidateIDs");
$add_IDs = count($linkIDs)? " AND link.LinkId IN ($linkIDs)" : "";
$linkIDs_array = explode(",", $linkIDs);
$NumLinks = $objConfig->Get("TotalVal");
$LinkIndex = $NumLinks - count($linkIDs_array);
// print($LinkIndex);
}
$ValidationType = "Temp";
$sql.= $add_IDs." LIMIT 0,".$LinksPerLoad;
$add_refreshUrl = "&ValSelected=1&EmptyUrl=".$EmptyUrl;
}
else
{
if ($_GET['refresh'] != 1)
{
$StartTime = $objConfig->Get("StartValidationTime");
// Get Count Total
$NumLinks = $objConfig->Get("TotalVal");
if (empty($NumLinks))
{
$NumLinks = QueryCount($sql);
$objSession->SetVariable("TotalVal", $NumLinks);
}
if (empty($StartTime))
{
$objConfig->Set("StartValidationTime", $CurrTime, 0, TRUE);
$objConfig->Save();
$StartTime = $CurrTime;
}
// Current Counter Position
$sql1 = $sql." AND ((val.ValidationTime > $StartTime) OR (val.ValidationTime='0'))";
$sql.= " AND ((val.ValidationTime <= $StartTime) OR (val.ValidationTime='0') OR val.ValidationTime IS NULL)";
$LinkIndex = QueryCount($sql1);
// echo $sql1."-".$sql;die();
}
else
{
// Get Count Total
$NumLinks = QueryCount($sql);
$objSession->SetVariable("TotalVal", $NumLinks);
$objConfig->Set("StartValidationTime", $CurrTime, 0, TRUE);
$objConfig->Save();
$StartTime = $CurrTime;
$LinkIndex = 0;
}
$sql.= " ORDER BY val.ValidationTime ASC LIMIT 0,".$LinksPerLoad;
$add_refreshUrl = "&EmptyUrl=".$EmptyUrl;
}
// echo htmlentities($sql, ENT_NOQUOTES)."
\n";
$objLinkList->EnablePaging = FALSE;
$objLinkList->Query_Item($sql);
$LinksCount = $objLinkList->NumItems();
/**** Define Socket variables *****/
$opened_sockets = 0;
$curr_obj = 0;
$sockets_name = "sock";
$sockets = array();
define ("MaxOpenedConnections", 5);
$FirstSockets = ($LinksCount > MaxOpenedConnections)? MaxOpenedConnections : $LinksCount;
// Init first sockets
for ($i=1; $i <= $FirstSockets; $i++)
$create_sockets[] = $sockets_name.$i;
/**** End Define Socket variables *****/
if ($LinksCount)
{
while (($LinksCount > $curr_obj) || $opened_sockets)
{
// Create New / Destroy Completed Sockets
if (count($create_sockets))
{
foreach ($create_sockets as $curr)
{
// Update Link status and Destroy socket
if (is_object($sockets[$curr]))
{
$objSocket = &$sockets[$curr];
$ValStatus = $objSocket->_validation_status? 1 : 2;
if (strlen($objSocket->_socket_return_code))
$ValCode = $objSocket->_socket_return_code;
else
$ValCode = $objSocket->_socket_output;
$CompletedLinks[] =
array('LinkId' => $objSocket->_socket_LinkId,
'LinkValidationId' => $objSocket->_socket_LinkValidationId,
'ValidationTime' => adodb_mktime(),
'ValidationStatus' => $ValStatus,
'ValidationCode' => $ValCode);
$objSocket->socket_disconnect();
unset($objSocket);
unset($sockets[$curr]);
$opened_sockets--;
if (!$opened_sockets)
{
// echo $opened_sockets." ".$curr_obj;
}
}
elseif (($curr_obj >= $LinksCount) && !$opened_sockets)
break;
// Don't open more sockets
if ($curr_obj < $LinksCount)
{
// Get Next Link Object
$_successfull = FALSE;
do
{
$l = &$objLinkList->GetItemRefByIndex($curr_obj);
if (is_object($l))
{
// Link Data
$URL = $l->Get("LinkUrl");
$LinkId = $l->Get("LinkId");
$LinkValId = $l->Get("LinkValidationId");
// Create new socket
$sockets[$curr] = new Socket($URL, $LinkId, $LinkValId); // If URL is not empty
/*
echo "OUTPUT
";
echo $sockets[$curr]->socket_read_all();
echo "END OUTPUT
";
*/
// echo "
"; print_r($l); echo "
SOCKETS TO CREATE: "; print_r($create_sockets); echo "
"; $o .= "
"; print $o."\n"; print " |