It Send Notification to android devices registered in the mysql database. this is the php code i'm using. and it's working well as far as i can tell.
<?php
$con = mysql_connect("*******.*****.com","*******","*********");
mysql_select_db("*******",$con);
$result1 = mysql_query("SELECT Device_ID FROM Registered_Users") or die(mysql_error());
$api_key = "***************-***********";
$response["products"] = array();
while ($row = mysql_fetch_array($result1))
{
$reg_id = array($row['Device_ID']);
$registrationIDs = $reg_id;
$message = $_POST['msg'];
$url = 'https://android.googleapis.com/gcm/send';
$fields = array('registration_ids' => $registrationIDs,'data'
=> array( "message" => $message ),);
$headers = array('Authorization: key='
. $api_key,'Content-Type: application/json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch);
curl_close($ch);
}
echo "success";
?>
my question is : how can i improve this code to get the best performance " results " possible ?