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 "

"; if ($sockets[$curr]->_socket_status != SOCKET_URL_ERROR) { $_successfull = TRUE; $sockets[$curr]->socket_connect($sockets[$curr]->_socket); $sockets[$curr]->_socket_name = $curr; $opened_sockets++; // echo "SOCKET STATUS: ".($sockets[$curr]->_socket_status)."
"; } else { $ValStatus = $_GET['EmptyUrl']? 2 : 1; $CompletedLinks[]= array('LinkId' => $sockets[$curr]->_socket_LinkId, 'LinkValidationId' => $sockets[$curr]->_socket_LinkValidationId, 'ValidationTime' => adodb_mktime(), 'ValidationStatus' => $ValStatus, 'ValidationCode' => 'EmptyUrl'); unset($sockets[$curr]); } $curr_obj++; } else // Went through all necessary Link Objects { break; } } while(!$_successfull); } } unset($create_sockets); } // Work with All sockets in order if ($opened_sockets && (is_array($sockets) && count($sockets))) { foreach ($sockets as $curr => $objSocket) { unset($objSocket); $curr_sock = &$sockets[$curr]; // Socket just opened if ($curr_sock->_socket_status == SOCKET_OPENED) { ## Prepare URL request $curr_sock->prepare_url_request(); ## Switch status to "Write to SOCKET" $curr_sock->_socket_status = SOCKET_WRITE; } // Just read from socket elseif ($curr_sock->_socket_status == SOCKET_READ) { // echo "TOTAL READING TIME: ".($curr_sock->_socket_read_time)." - ".($curr_sock->_socket_read_timeout)."
"; ## Reading Timeout Check if ($curr_sock->_socket_read_time >= $curr_sock->_socket_read_timeout) { $create_sockets[] = $curr; continue; } else { $start_time = getmicrotime(); $socket_read = $curr_sock->socket_read(); $curr_sock->_socket_read_time = $curr_sock->_socket_read_time + (float)(getmicrotime() - $start_time); if ($socket_read) { $curr_sock->parse_output($curr_sock->_socket_output_last_line); } elseif ($curr_sock->_socket_read_status) { // Check if socket dead if (!$curr_sock->_socket) { // echo "HERE? socket dead"; $create_sockets[] = $curr; continue; } } else { // echo "CATNT READ: ".($curr_sock->_URL)."; READ STATUS: ".($curr_sock->_socket_read_status)."; LAST LINE: ".($curr_sock->_socket_output_last_line)." TOTAL READ TIME: ".($curr_sock->_socket_read_time)."; SOCKET STATUS: ".($curr_sock->_socket_status)."

"; } // Check if got correct response if ($curr_sock->_socket_status == SOCKET_COMPLETED) { // echo "HERE? socket completed"; $create_sockets[] = $curr; continue; } elseif (feof($curr_sock->_socket)) { // echo "HERE? socket dead"; $create_sockets[] = $curr; $curr_sock->_socket_status = SOCKET_EOF; continue; } } } elseif ($curr_sock->_socket_status == SOCKET_WRITE) { // echo "WRITE REQUEST: ".$curr_sock->_socket_request_line."
"; if (!$curr_sock->socket_write($curr_sock->_socket_request_line)) { // echo "HERE? CANT NOT WRITE TO SOCKET"; // Free socket and to create next list if writing is unsuccessfull $create_sockets[] = $curr; continue; } else { // Set status to "READ back from SOCKET" $curr_sock->_socket_status = SOCKET_READ; } } elseif ($curr_sock->_socket_status == SOCKET_OPEN_ERROR) { // Free socket and to create next list $create_sockets[] = $curr; continue; } // Check if socket dead elseif (!$curr_sock->_socket) { // echo "HERE? socket dead"; $create_sockets[] = $curr; continue; } } // echo "
SOCKETS TO CREATE: "; print_r($create_sockets); echo "

"; } } } // Update Complete Links if (count($CompletedLinks)) { $objItemDB = new clsItemDB(); $objItemDB->tablename = GetTablePrefix()."LinkValidation"; // $fp = fopen("/home/sites/dev1/in-portal/logs.txt", "w"); foreach ($CompletedLinks as $curr_el) { // Logging if ($curr_el['ValidationStatus'] != 1) { // $data = join("\n", $curr_el)."\n\n"; // @fputs($fp, $data, strlen($data)); } // echo "LinkID: ".$curr_el['LinkId']." status: ".$curr_el['ValidationStatus']."

"; if (!empty($curr_el['LinkValidationId'])) { $currLinkId = $curr_el['LinkId']; unset($curr_el['LinkId']); $objItemDB->m_dirtyFieldsMap = $objItemDB->Data = $curr_el; $objItemDB->id_field = "LinkValidationId"; $objItemDB->Update(); } else { $currLinkId = $curr_el['LinkId']; unset($curr_el['LinkValidationId']); $objItemDB->Data = $curr_el; $objItemDB->NoResourceId = TRUE; $objItemDB->Create(); } $CompletedSockets[] = $currLinkId; } // fclose($fp); } // print_r($CompletedSockets); // Update Validated LinksID for Temporarily Validation if (($ValidationType == "Temp") && count($CompletedSockets)) { $linkIDs = array_diff($linkIDs_array, $CompletedSockets); $linkIDs_string = count($linkIDs)? implode(",", $linkIDs) : ""; if (strlen($linkIDs_string)) { $objSession->SetVariable("LinkValidateIDs", $linkIDs_string); // echo "Completed: "; print_r($CompletedSockets); echo "
"; // echo "NEW LInks: ".$linkIDs_string." => ".$NumLinks."-".$LinksCount; } else { $objSession->SetVariable("", $linkIDs_string); $NumLinks = 0; } } $title = prompt_language("la_Text_Link_Validation"); int_header(NULL,NULL, $title); ?> " ; print "setTimeout(\"document.location='$target';\", 40);"; print " "; } else { $CancelURL = $rootURL."in-link/admin/validation.php?env=".BuildEnv()."&ResetPage=1"; $caption = prompt_language("la_prompt_runlink_validation")." ($LinkIndex / $NumLinks)"; stats($caption, $LinkIndex, $NumLinks); reload($_SERVER["PHP_SELF"]. "?env=".BuildEnv().$add_refreshUrl); } function stats($caption,$myprogress,$totalnum) { global $rootURL, $CancelURL, $PageTitle; if($totalnum>0) { $pct=round(($myprogress/$totalnum)*100); } else $pct = 100; $o .="
"; print "\n"; $o .= int_subsection_title_ret($caption." - ".$pct."%"); $o .= "

"; $o .= " "; $o .=" "; $comp_pct = 100-$pct; $o .= " "; $o .= "
 
"; $o .= "
"; print $o."\n"; print "
"; } function reload($url) { print ""; //echo "Next "; } ?>