$con = mysqli_connect("localhost", "m_health", "m_health", "mhealth"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $date_now = strtotime("now"); $date_yday = strtotime("-1 day"); $result = mysqli_query($con, "SELECT * FROM tip where schedule_time between '{$date_yday}' and '{$date_now}'"); //var_dump($result); while ($row = mysqli_fetch_array($result)) { $res = db_query("select * from sdp_subscription b join sdp_services s on s.service_id = b.service_id where s.reference_id = :rid", array('rid' => $row['category_id'])); //var_dump($res); foreach ($res as $r) { $url = "http://localhost/SDPSouthAfrica/sendsms.php?address=" . urlencode($r->USER_ID) . "&msg=" . urlencode($row['gist']) . "&service=" . urlencode($r->SERVICE_ID) . "&sender=" . urlencode($r->SENDER_ID); echo $r->USER_ID . '<br>' . $row['gist'] . '<br>' . $url . '<br>' . $r->SERVICE_ID . '<br>'; $resp = do_response($url); echo '<br>'; var_dump($resp); echo '<br><br>'; } } mysqli_close($con); function do_response($url) { try { # try pushing request to url; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPGET, 1); // Make sure GET method it used curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return the result
function process_alert_queue($conf) { $dir = '/var/www/html/mmarket/'; $username = $conf['gw_username']; $password = $conf['gw_password']; $to_url = $conf['gateway']; $msg2 = $conf['msg2']; // for consumer $msg3 = $conf['msg3']; // for provider $alert_log = $dir . 'alert_queue.log'; /* $f = fopen($alert_log); $line = fgets($f); fclose($f); * */ //$array1 = explode('>>', $line); $line = `head -n1 {$alert_log}`; $array2 = explode(';', $line); $consumer = $array2[0]; $provider = $array2[1]; $sender = $conf['sender']; # first send to consumer $params = "U={$username}&P={$password}&S=" . urlencode($sender) . "&D=" . urlencode($consumer) . "&M=" . urlencode($msg2) . "&T=1"; $url = $to_url . '?' . $params; $res1 = do_response($url); log_alert_processing($consumer, $res1, $url); # then service provider $params2 = "U={$username}&P={$password}&S=" . urlencode($sender) . "&D=" . urlencode($provider) . "&M=" . urlencode($msg3) . "&T=1"; $url2 = $to_url . '?' . $params2; $res2 = do_response($url2); log_alert_processing($provider, $res2, $url2); # log this operation }