0

I have a problem in sending via CURL notifications to 19k users.

The new FB app notifications API is goldmine, so i've implemented a system into my app that notifies a player when his friend has a higher score than him. The problem is that the app has to send 19k notifications through curl and it takes ~950 hours. Is there a faster sollution to send these nitifications ? I mean i have seen most of the big players (like zynga) are succesfully using the app notifications and i don't thing they have less notifications to send than me :)

here's my code


    function _getAppToken(){
            $APPLICATION_ID = "xxxxxxx";
            $APPLICATION_SECRET = "xxxxxxxx";

            $token_url = "https://graph.facebook.com/oauth/access_token?" .
                "client_id=" . $APPLICATION_ID .
                "&client_secret=" . $APPLICATION_SECRET .
                "&grant_type=client_credentials";
            //$app_token = file_get_contents($token_url);
            $accessToken = explode('=', file_get_contents($token_url));
            return $accessToken[1];
        }


    function _curlDoNotifications($fb_id, $tokennn, $mesaj, $hrf = '')
        {
            $attachment = array(
                'access_token' => $tokennn,
                'href' => $hrf,
                'template' => $mesaj
            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' . $fb_id . '/notifications');
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); //to suppress the curl output
            $result = curl_exec($ch);
            curl_close($ch);
            return $result;
        }

First function takes the app token and use it to send the notification through the second function (curl).

foreach user that has app installed and has to be notified i apply those 2 functions. The thing is that the second function lasts ~3 secs/user

thanks

LATER EDIT: api batch sending is the answer :) which can send max 50 notifications at a time

2
  • 1
    19K users, “goldmine” … this smells rather spammy. Anyway, to speed things up you can use batch requests – those lower the number of HTTP requests necessary, and therefor the overall time needed to send the notifications.
    – CBroe
    Oct 24, 2012 at 15:53
  • no, it's not spammy at all. i notify user friends which has lower scores than him. The app actually has 240k users. ;) Actually the batch works just fine (with a php daemon tied to it) => instant 1:1 notifications Oct 24, 2012 at 16:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.