//#debug exit(print_r($agents, true) . print_r($typeids, true) . "\n" . $siteid . "\n"); /*try to read the stats from remote server*/ $url = sprintf('http://affserver.globalmailer.com/getPromocodeStatXml.asp' . '?RepPass=2idf8iun234o8idsfkljsda' . '&FromDate=%s&ToDate=%s', $date, $date); //#debug echo $url . "\n"; $retimes = 0; $xml = simplexml_load_file($url); while ($xml === false) { $retimes++; sleep(35); $xml = simplexml_load_file($url); if ($retimes == 3) { break; } } if ($xml === false) { $mailinfo = __phpmail("*****@*****.**", "IML STATS GETTING ERROR, REPORT WITH DATE: " . date('Y-m-d H:i:s') . "(retried " . $retimes . " times)", "<b>FROM WEB02</b><br><b>--ERROR REPORT</b><br>"); exit(sprintf("Failed to read stats data.(%s)(%d times)\n", $mailinfo, $retimes)); } $i = $j = $m = 0; foreach ($xml as $key => $value) { /*# debug echo "promocode: " . $value->promocode . "\n"; echo "clicks: " . $value->clicks . "\n"; echo "free: " . $value->free . "\n"; echo "signups: " . $value->signups . "\n\n"; */ if (in_array($value->promocode, array_keys($agents))) { //compare promocode as campaignid but not agent username //#debug echo $value->promocode . "," . $agents['' . $value->promocode] . ";\n"; continue; /* * try to put stats data into db
} /*try to read stats data*/ $srclink = 'http://www.pimpmansion.com/user/view_details.php?xml=1' . '&username=aquablue@cleanchattersinc.com&password=cxriscross611' . '&campaign_id=%s&form1_submit1=Show&form1_select2=%s&form1_select3=%s&form1_select4=%s&'; $sql = sprintf('select * from view_mappings where siteid = %d', $siteid); $rs = mysql_query($sql, $zconn->dblink) or die("Something wrong with: " . mysql_error()); $i = $j = $k = $m = 0; while ($row = mysql_fetch_assoc($rs)) { if (empty($row['campaignid'])) { echo "Warning!!! Agent " . $row['username'] . " has no campaigns!!!\n"; continue; } $url = sprintf($srclink, $row['campaignid'], $ymd[2], $ymd[1], $ymd[0]); //echo $url . "\n"; $doc = new DOMDocument(); if (!$doc->load($url)) { $mailinfo = __phpmail("*****@*****.**", "HORNM STATS GETTING ERROR, REPORT WITH DATE: " . date('Y-m-d H:i:s'), "<b>FROM WEB02</b><br/><b>--ERROR REPORT</b><br/>"); exit(sprintf("Failed to read stats data.(%s)\n", $mailinfo)); } $items = $doc->getElementsByTagName("item"); $doc = null; $uniques = 0; $chargebacks = 0; $signups = 0; $sales = 0; foreach ($items as $item) { $uniques += getValueByName($item->childNodes, "visits"); $chargebacks += getValueByName($item->childNodes, "refunds"); //actually not useful any more $signups += getValueByName($item->childNodes, "signups"); $sales += getValueByName($item->childNodes, "sales"); }
/* * and we change and optimize the above 3 lines as the following block goes */ $retimes = 0; $toptimes = 2; $response = file_get_contents($url); while ($response === false) { $retimes++; sleep(35); $response = file_get_contents($url); if ($retimes == $toptimes) { break; } } if ($response === false) { $mailinfo = __phpmail("*****@*****.**", "LCD (on PDD) STATS GETTING ERROR, REPORT WITH DATE: " . date('Y-m-d H:i:s') . "(retried " . $retimes . " times)", "<b>FROM WEB02</b><br><b>--ERROR REPORT</b><br>"); exit(sprintf("Failed to read stats data.(%s)(%d times)\n", $mailinfo, $retimes)); } //echo "var_dump\n";//for debug //var_dump($response);//for debug //echo "var_dump\n";//for debug $xml = simplexml_load_string($response); if ($xml === false) { exit(sprintf("\nFailed to parse stats data.\n")); } $i = $j = $m = $f = 0; foreach ($xml->children() as $item) { $attr = $item->attributes(); /* echo 'node id ' . $attr['id'] . " => " . "date: " . $item->date
if ($rss_7 === false) { exit(sprintf("Failed to read stats data from %s.\n", $link)); } */ $rss_7 = array(); $link = $rsssrclink . '&program=8'; $rss_8 = fetch_rss($link); if ($rss_8 === false) { $mailinfo = __phpmail("*****@*****.**", "CAM4 STATS GETTING ERROR (program=8), REPORT WITH DATE: " . date('Y-m-d H:i:s'), "<b>FROM WEB02</b><br><b>--ERROR REPORT</b><br>"); echo $mailinfo . "\n"; exit(sprintf("Failed to read stats data from %s.\n", $link)); } $link = $rsssrclink . '&program=10'; $rss_10 = fetch_rss($link); if ($rss_10 === false) { $mailinfo = __phpmail("*****@*****.**", "CAM4 STATS GETTING ERROR (program=10), REPORT WITH DATE: " . date('Y-m-d H:i:s'), "<b>FROM WEB02</b><br><b>--ERROR REPORT</b><br>"); echo $mailinfo . "\n"; exit(sprintf("Failed to read stats data from %s.\n", $link)); } array_push($rss, $rss_5); array_push($rss, $rss_7); array_push($rss, $rss_8); array_push($rss, $rss_10); } else { echo "Only 1 parameter allowed, like '2010-03-01,12:34:56'.\n"; exit; } $zconn = new zmysqlConn(); /*find out the typeids and siteid from db by "cam4" which is the abbreviation of the site*/ $typeids = array(); $siteid = null;
$j = $m = $n = 0; while ($row = mysql_fetch_assoc($rs)) { /*Try to user curl to get the data*/ $url = sprintf('http://www.sexywivesfinder.com/stats/stats-export.php?aff=%s&d1=%d&m1=%d&y1=%d&d2=%d&m2=%d&y2=%d', $row['campaignid'], $ymd[2], $ymd[1], $ymd[0], $ymd[2], $ymd[1], $ymd[0]); $scrape_ch = curl_init(); curl_setopt($scrape_ch, CURLOPT_URL, $url); curl_setopt($scrape_ch, CURLOPT_USERPWD, "cleanchatters:LKMSAL91"); curl_setopt($scrape_ch, CURLOPT_RETURNTRANSFER, true); $scrape = curl_exec($scrape_ch); curl_close($scrape_ch); //echo $row['username'] . "\n" . $scrape . "\n"; $lines = explode("\n", $scrape); if (count($lines) < 2) { $errmsg = sprintf("It should have 2 lines at least for agent %s.\n", $row['username']); echo $errmsg; $mailinfo = __phpmail("*****@*****.**", "SWF STATS GETTING ERROR, REPORT WITH DATE: " . date('Y-m-d H:i:s'), "<b>FROM WEB02</b><br><br>" . "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" . str_replace("\n", "<br/>", $scrape) . "<br/>" . $errmsg . "<br/>" . "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" . "<br><br/><b>--ERROR REPORT</b><br/>"); echo $mailinfo . "\n"; continue; } $k = explode(",", $lines[0]); for ($i = 0; $i < count($k); $i++) { $k[$i] = trim($k[$i]); } $v = explode(",", $lines[1]); for ($i = 0; $i < count($v); $i++) { $v[$i] = trim($v[$i]); } $stats = array_combine($k, $v); //echo print_r($stats, true); /* * Try to put data into db.
exit("At least 1 parameter needed like '2010-05-01,12:34:56'.\n"); } $threshold = 15; if ($argc - 1 >= 2) { $threshold = $argv[2]; if (!is_numeric($threshold) || $threshold < 1) { exit("Threshold must be an integer and bigger than 0.\n"); } } /* * the following line will make the whole script exit if date string format is wrong */ $date = __get_remote_date($argv[1], "America/New_York", -5); $date_l = __get_remote_date($argv[1], "America/New_York", -5, "America/New_York", true); $zconn = new zmysqlConn(); $sql = sprintf("select * from dup_stats where convert(trxtime, date) = '%s'" . " and (raws >= %d or uniques >= %d or chargebacks >= %d or signups >= %d or frauds >= %d or sales_number >= %d)" . " order by trxtime desc", $date, $threshold, $threshold, $threshold, $threshold, $threshold, $threshold); //echo $sql . "\n"; //for debug $rs = mysql_query($sql, $zconn->dblink) or die("Something wrong with: " . mysql_error()); if (mysql_num_rows($rs) != 0) { $lines = ''; while ($r = mysql_fetch_assoc($rs)) { foreach ($r as $k => $v) { $lines .= $k . ":" . $v . " | "; } $lines .= "\n"; } $mailinfo = __phpmail("*****@*****.**", "AWL STATS ALERTS ({$date_l}, threshold: {$threshold}, row(s): " . mysql_num_rows($rs) . ")", $lines); exit($mailinfo . " ({$date_l})\n"); } else { echo "No alerts. ({$date_l})\n"; }