Jump to content

Recommended Posts

Hello 

I have 100000 users , I am alwyes send information, In fact this information don't reach to all users , I don't know why ?

I will attach send php files . and please see what is wrong of this flie and which logic I can use . Note if I change 1000 number to 3000 no user receive also I don't know why 
------------------------------------

 

 

<?php
include('session.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
 <?php
header('Content-type: text/html; charset=utf-8');
  //generic php function to send GCM push notification
   function sendPushNotificationToGCM($registatoin_ids, $message) {
//Google cloud messaging GCM-API url
 
 
 
        $fields = array(
            'registration_ids' => $registatoin_ids,
            'data' => $message,
        );
 
define("GOOGLE_API_KEY", "AIzaSyB2x2jNi94zypUX_bqfYkhyuhrTwK0IG2XJ8");//saeed    
//define("GOOGLE_API_KEY", "AIzaSyDYoI9libqfYkhyuhr-rxGW_G0TVDUe4dg");//amjad   
 
        $headers = array(
            'Authorization: key=' . GOOGLE_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_SSL_VERIFYHOST, 0); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
//curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
        $result = curl_exec($ch);       
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }
        curl_close($ch);
        return $result;
    }
?>
 
<?php
header('Content-type: text/html; charset=utf-8');
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
 
if (isset($_GET['level']) &&isset($_GET['m1']) &&isset($_GET['m2']) &&isset($_GET['m3']) &&isset($_GET['m4']) &&isset($_GET['m5']) &&isset($_GET['m6']) &&isset($_GET['m7'])){
$level=$_GET['level'];
 
 
$m1=$_GET['m1'];
$m2=$_GET['m2'];
$m3=$_GET['m3'];
$m4=$_GET['m4'];
$m5=$_GET['m5'];
$m6=$_GET['m6'];
$m7=$_GET['m7'];
 
 
$m11=mysql_real_escape_string($_GET['m1']);
$m21=mysql_real_escape_string($_GET['m2']);
$m31=mysql_real_escape_string($_GET['m3']);
$m41=mysql_real_escape_string($_GET['m4']);
$m51=mysql_real_escape_string($_GET['m5']);
$m61=mysql_real_escape_string($_GET['m6']);
$m71=mysql_real_escape_string($_GET['m7']);
 
mysql_query("SET NAMES 'utf8'");
$resultaa = mysql_query("INSERT words (id, level, m1, m2, m3, m4, m5, m6, m7) VALUES (NULL,'$level','$m11','$m21','$m31','$m41','$m51','$m61','$m71')");
$id = mysql_insert_id();
 
if($level == 0){
$result = mysql_query("SELECT Rid FROM users ");
 
}else{
$result = mysql_query("SELECT Rid FROM users where level = '$level' OR level = '4'");
//$result = mysql_query("SELECT Rid FROM users where level = '$level'");
}
 
$message = array(
'word_id' => $id,
'm1' => $m1,
'm2' => $m2,
'm3' => $m3,
'm4' => $m4,
'm5' => $m5,
'm6' => $m6,
'm7' => $m7,
'level' => $level
);
 
if (mysql_num_rows($result) > 0) {
for($counter = 0; $counter<mysql_num_rows($result) ; $counter+=1000){
$gcmRegIds=array();
for($counter2=$counter ; $counter2<$counter+1000;$counter2++){
if($counter2<mysql_num_rows($result)){
$row = mysql_fetch_array($result);
$gcmRegIds[]=$row["Rid"];
 
}
}
 
$pushStatus = sendPushNotificationToGCM($gcmRegIds, $message);
echo $pushStatus;
 
}
 
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
echo "Process Time: {$time}";
 
 
}else {
$response["success"] = 0;
$response["message"] = "No user found";
echo json_encode($response);
}
 
 
 
 
 
 
 
//echo $result;
else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
 
// echoing JSON response
echo json_encode($response);
?>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/300846-which-logic-i-can-use/
Share on other sites

You need to split it into chunks of no more than 1,000 and send each chunk.

 

Can't really help what google cloud messaging limits are.

 

I could think of a way to do this.

Create a column named sent with a 0/1,y/n,null/1 value or whatever suits you.

Do a mysql query with a LIMIT of 1,000 for any messages not sent yet.

 AND sent IS NULL LIMIT 1000 (providing set default values as null)

 

If you need to send them exact orders query them by lowest id as well

 

Set the messages sent column in mysql to a 1 to mark them as sent.

Have a cron job running the script a timely manner, allowing ample time to complete 1,000 messages being sent via GCM.

 

Breaking them up to even less than 1,000 will also work providing set your cron time more frequently.

One Very Important Thing would be to convert to using some other database interface. The 'mysql' one is deprecated meaning "out of favor, not supported, and gone in the latest version of PHP". So - while trying to solve this you might make the change to use either mysqlI or PDO and save yourself another rewrite down the road.

 

You might also explore how to write your code so that the logic (php) is separated from the presentation (html) to make it easier to read and to maintain and easier for others to follow. Place your html at the end (I put it all in a function) and place php vars in the html where you have dynamic content. Then at the beginning do all your input verifications and data lookups and assembling of the dynamic content into those php vars. Then call the function to display all the content. You will have a MUCH cleaner script that a stranger can more easily walk up to and attempt to understand and help with. I may be strange but 99% of my scripts have just one set of php tags (<?php/?>) in them.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.