<?php $table = 'campaignsN'; $minutesSinceLastOpened = 60; //desktop MediaMath $devices = ["'Desktop'", "'Mobile'"]; $platforms = ["'MediaMath'", "'Appnexus'"]; foreach ($devices as $device) { foreach ($platforms as $platform) { $qry_em = "select max(ts) as ts from {$table} where device={$device} and platform={$platform} ;"; $qry_res = mysqli_query($con, $qry_em); $row = mysqli_fetch_array($qry_res, MYSQLI_ASSOC); $ts = $row['ts']; if (timeDiffToBig($ts, $minutesSinceLastOpened)) { $alert = "CAMP OPENER ALERT - we have not opened a campaign in {$device} , {$platform} . Last one was opened at {$ts} and now {$date}"; send_mail($alert); //send_sms_mail($alert); } } } function timeDiffToBig($ts, $maxDiff) { $date = getTime(); $diffInMinutes = abs(strtotime($ts) - strtotime($date)) / 60; if ($diffInMinutes > $maxDiff) { return true; } else { return false; } }
<?php $table = 'campaignsN'; $minutesSinceLastChanged = 20; //desktop MediaMath $devices = ["'Desktop'", "'Mobile'"]; $platforms = ["'MediaMath'", "'Appnexus'"]; foreach ($devices as $device) { foreach ($platforms as $platform) { $qry_em = "select max(updTS) as ts from campaignsN where device={$device} and platform={$platform} and updTS>ts ; "; $qry_res = mysqli_query($con, $qry_em); $row = mysqli_fetch_array($qry_res, MYSQLI_ASSOC); $ts = $row['ts']; if (timeDiffToBig($ts, $minutesSinceLastChanged)) { $date = getTime(); $alert = "CAMP POSITIVE ALERT - no positive camps where changed in {$device} , {$platform} . Last one was changed at {$ts} and now {$date}"; send_mail($alert); //send_sms_mail($alert); } } } function timeDiffToBig($ts, $maxDiff) { $date = getTime(); $diffInMinutes = abs(strtotime($ts) - strtotime($date)) / 60; if ($diffInMinutes > $maxDiff) { return true; } else { return false; } }