<?php
$SQL_SERVER_USER = "rosger";
$SQL_SERVER_PASSWORD = "19740910s";
$SQL_SERVER_TABLE = "agent";
$SQL_SERVER_HOST = "localhost";
$SQL_SERVER_PORT ="5432";
$SENDER_SERVER_PORT="71744";
$SENDER_SERVER_IP ="215.21.147.30";
$service_port = $SENDER_SERVER_PORT;
$service_addr = $SENDER_SERVER_IP;
// First.. Trying connect to SQL server
// If connecting failed sleep 5 seconds, and try again.
// until the connecting finished, break the while loop, go ahead to send out sms.
// connect to SQL server loop.
while (1)
{
$conn_checker = pg_connect("host=$SQL_SERVER_HOST port=$SQL_SERVER_PORT dbname=$SQL_SERVER_TABLE user=$SQL_SERVER_USER password=$SQL_SERVER_PASSWORD");
if ($conn_checker == false)
{
print "connect to SQL server fail..";
pg_close($conn_checker);
}
else
{
break;
}
sleep (5);
}
// sendout sms loop
while (1)
{
// get current time
$thesec = time ();
// select reserved messages from CallME reserve TABLE
$sql_sendout = "SELECT reserve,deliver_date,target,message,id FROM b WHERE (reserve < $thesec);";
$result_sendout = pg_query ($conn_checker,$sql_sendout);
// if could not read anything from reserve TABLE,
// there should be some error happened,
// the simplest way to solve the problem is shut down the SQL connect
// and re-establish it..
if ($result_sendout == false)
{
printf ("Counld not query from SQL server.. try again latter\n");
// break the connection
pg_close ($conn_checker);
// the same as the above main while loop.
while (1)
{
$conn_checker = pg_connect("host=$SQL_SERVER_HOST port=$SQL_SERVER_PORT dbname=$SQL_SERVER_TABLE user=$SQL_SERVER_USER password=$SQL_SERVER_PASSWORD");
if ($conn_checker == false)
{
print "connect to SQL server fail..";
pg_close($conn_checker);
}
else
{
break;
}
sleep (5);
}
continue;
}
// fingure out how many sms was reversed in reseve TABLE
$result_count = pg_num_rows ($result_sendout);
// for loop to send out the sms message one per connection to remote sms gateway
for ($result_ptr = 0; $result_ptr < $result_count; $result_ptr++)
{
// fetch message informations from SQL querying results.
$qr = pg_fetch_object($result_sendout, $result_ptr);
// setup the request URL.
$agentid = 2123;
$target =$qr->target;
$message =$qr->message;
$deliver_date =$qr->deliver_date;
$response_url ="http://61.218.68.20/~roger/testresponse.php";
$url ="http://211.21.147.30:7744/sendmessage.php?" .
"agentid=$agentid&" .
"target=$target&" .
"message=$message&" .
"deliver_date=$deliver_date&" .
"response_url=$response_url";
// create new socket descriptor for connecting to remote HTTP server
$fp_sender = fsockopen ($SENDER_SERVER_IP,$SENDER_SERVER_PORT, $errno_sender, $errstr_sender, 30);
// if error happened, skip this message a ahead to next one.
if (!$fp_sender)
{
echo ("CONNECT ERROR: $errstr_sender ($errno_sender)<br>\n");
echo($url);
continue;
}
printf ($fp_sender, "GET %s\n\n", $url);
// there are some other things should be done by yourself.
// first.
// READ response messages from REMOTE gateway.
// second.
// If the response shows that "it was sendout successfuly",
// delete this short message reserve record from reverse TABLE.
// and add one record to deliveXX table for that user.
// that's everything.
fclose ($fp_sender);
}
}
pg_close ($conn_checker);
?>
and then how can i follow that notes to achieve my project