_fetchMessages 100 file class_APNS.php - LIMIT 100

675 views
Skip to first unread message

spring

unread,
Feb 26, 2012, 12:08:34 PM2/26/12
to Easy APNs
Hi ,

there is "LIMIT 100" in the fetch messages
in my database I got 50,000 devices and if I start send 100 messages
every one minute it will take hours !!!

why LIMIT set to 100 ?
can I change it to 10000 ? so send will take 5 minutes ?

Thanks,
Yossi.



Following the PHP code I'm taking about:

private function _fetchMessages(){
// only send one message per user... oldest message first
$sql = "SELECT
`apns_messages`.`pid`,
`apns_messages`.`message`,
`apns_devices`.`devicetoken`,
`apns_devices`.`development`
FROM `apns_messages`
LEFT JOIN `apns_devices` ON (`apns_devices`.`pid` =
`apns_messages`.`fk_device` AND `apns_devices`.`clientid` =
`apns_messages`.`clientid`)
WHERE `apns_messages`.`status`='queued'
AND `apns_messages`.`delivery` <= NOW()
AND `apns_devices`.`status`='active'
GROUP BY `apns_messages`.`fk_device`
ORDER BY `apns_messages`.`created` ASC
LIMIT 100;";

John Jones

unread,
Feb 26, 2012, 2:07:24 PM2/26/12
to easy...@googlegroups.com, Easy APNs
Note apple does not like you opening and closing the request to send one message, i have been able to open and send 250 at a time with no issue, at present i am testing combining 250 messages into one packet then sending 250 of them, hence getting a throughput of 250x250 each send ;)

Sent from my iPhone

> --
> You received this message because you are subscribed to the Google
> Groups "Easy APNS" group.
> To post to this group, send email to easy...@googlegroups.com
> To unsubscribe from this group, send email to
> easyapns+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/easyapns?hl=en

spring

unread,
Feb 27, 2012, 7:26:34 AM2/27/12
to Easy APNs
Hi John,

Can you help with that , I have 50,000 users on my SQL database
To send broadcast will take me 8 hours , if set crown job to every one
minute

Can we just leave connection open and send all messages ?,


Thanks,
Yossi

HOn Feb 26, 9:07 pm, John Jones <j...@cytefx.com> wrote:
> Note apple does not like you opening and closing the request to send one message, i have been able to open and send 250 at a time with no issue, at present i am testing combining 250 messages into one packet then sending 250 of them, hence getting a throughput of 250x250 each send ;)
> N
> Sent from my iPhone

spring

unread,
Feb 26, 2012, 3:38:14 PM2/26/12
to Easy APNs
Hi John,

that sound much more powerful sending as for today I have 50,000
tokens
if I set crow job for minute (minimum) it will take more the eight
hours for broadcast ?!

It will be great if possible for you to share the combing code so in
one shut I can send all messages (250x250=62,500>50,000)


Regards,
Yossi

On Feb 26, 9:07 pm, John Jones <j...@cytefx.com> wrote:
> Note apple does not like you opening and closing the request to send one message, i have been able to open and send 250 at a time with no issue, at present i am testing combining 250 messages into one packet then sending 250 of them, hence getting a throughput of 250x250 each send ;)
>
> Sent from my iPhone
>

John Jones

unread,
Feb 27, 2012, 1:07:36 PM2/27/12
to easy...@googlegroups.com
Hi

There is some code here

http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/

That will help you on the way, of keeping open the door to the server whilst you loop.

What I have done on top of that is combined multiple messages together. (concatenate the packets)

John

Yossi Cohen

unread,
Feb 27, 2012, 1:44:55 PM2/27/12
to easy...@googlegroups.com, easy...@googlegroups.com
Hi John ,

Thanks for the link , I guess it refers to the following part:

for($index=0; $index<=count($deviceTokens); $index++)
{
$deviceToken = $deviceTokens[$index];
$payload = json_encode($body);
$msg = chr(0) . pack(”n”,32) . pack(’H*’, str_replace(’ ‘, ”, $deviceToken)) . pack(”n”,strlen($payload)) . $payload;
print “sending message :” . $msg . “\n”.”";
$ret = fwrite($fp, $msg);
echo “Return=”.$ret.”";
}



Im trying to think how to change easyapns code to support that , and thought to ask about the loop what is the maximum count it can run , is it 250, as your pervious mail , or I can make it run on all 50,000 messages I got in my SQL ?

Thanks!,
Yossi

John Jones

unread,
Feb 27, 2012, 4:57:45 PM2/27/12
to easy...@googlegroups.com
Hi

you could try to run all 50,000 at once, but it could time out, so what I did was put a loop around this, that I could interrupt if needed.

You have to remember that you are blocking a request by sending out to apple, and loosing capacity whilst sending the messages.

J

Yossi Cohen

unread,
Feb 28, 2012, 12:32:59 AM2/28/12
to easy...@googlegroups.com
Thanks for the answer,
Im very much curious to test and see how much time it will take the server (Linux) to send all 50,000 messages

You wrote that It will "block request"
Do you mean to iPhones request to register or do other request ?

For "loosing capacity" do you mean that the server will run slow at that sending time ?

John Jones

unread,
Feb 28, 2012, 12:20:57 PM2/28/12
to easy...@googlegroups.com
Basically if your webserver is set to connecto to apple and send these over that thread is effectivly lost whilst its performing that task.

Blocking is stoping the thread in this case.

J

bagusflyer

unread,
Mar 3, 2012, 7:29:19 PM3/3/12
to Easy APNs
My question is how you combine 250 message into one packet?

Just combine those JSON data before sending to Apple?

On 2月29日, 上午1时20分, John Jones <j...@cytefx.com> wrote:
> Basically if your webserver is set to connecto to apple and send these over that thread is effectivly lost whilst its performing that task.
>
> Blocking is stoping the thread in this case.
>
> J
> On 28 Feb 2012, at 05:32, Yossi Cohen wrote:
>
>
>
>
>
>
>
> > Thanks for the answer,
> > Im very much curious to test and see how much time it will take the server (Linux) to send all 50,000 messages
>
> > You wrote that It will "block request"
> > Do you mean to iPhones request to register or do other request ?
>
> > For "loosing capacity" do you mean that the server will run slow at that sending time ?
>

John Jones

unread,
Mar 4, 2012, 2:57:05 AM3/4/12
to easy...@googlegroups.com, Easy APNs
Yep

Sent from my iPhone

Bagusflyer

unread,
Mar 7, 2012, 8:01:23 PM3/7/12
to easy...@googlegroups.com
But I have another question, if I combine multiple messages into one packet how am I suppose to deal with the feedback? I can only check the feedback one by one, if I combine multiple messages into one packet, how can I know which one is failed ?

Thanks,
Zhou Hao

meticulo

unread,
Mar 8, 2012, 11:35:45 AM3/8/12
to Easy APNs
Sorry to throw in a further question but I have a app that expects to
see 100,000s of thousands of users. Do I just combine all those
messages into one packet?

On Mar 7, 8:01 pm, Bagusflyer <bagusfl...@gmail.com> wrote:
> But I have another question, if I combine multiple messages into one packet how am I suppose to deal with the feedback? I can only check the feedback one by one, if I combine multiple messages into one packet, how can I know which one is failed ?
>
> Thanks,
> Zhou Hao
>
> 在 2012-3-4,下午03:57, John Jones 写道:
>
>
>
>
>
>
>
> > Yep
>
> > Sent from my iPhone
>

John Jones

unread,
Mar 8, 2012, 1:57:31 PM3/8/12
to easy...@googlegroups.com, Easy APNs
You can try, but i think apple has a limit on the max data you can write on one connection.

If i try to send 1000 in one go the file size status returned does not go above 68000 and i think thats a limit, hence forming them to 250 packets of messages thenll looping ocer them writes

Sent from my iPhone

Keith Ray

unread,
Mar 8, 2012, 1:44:22 PM3/8/12
to easy...@googlegroups.com
You can't put 100,000 of anything into the Push Notification payload. You COULD fit close to 240 1-byte identifiers into one payload, fewer for 2-byte identifiers, fewer still for 4-byte identifiers.

Really, your app should directly query your server to get the updated info for 100,000 users; doing so in response to a Push Notification or when the user launches your app and there hasn't been a Push Notification lately.

"Each push notification carries with it a payload. The payload specifies how users are to be alerted to the data waiting to be downloaded to the client application. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit. Remember that delivery of notifications is “best effort” and is not guaranteed."

--
C. Keith Ray
twitter: @ckeithray
phone: 650-KEY-4RAY
650-539-4729
http://agilesolutionspace.blogspot.com/

meticulo

unread,
Mar 9, 2012, 1:37:54 PM3/9/12
to Easy APNs
So I cant use Easy Apns to send 1 message to 100,000 users?

On Mar 8, 1:44 pm, Keith Ray <keith....@gmail.com> wrote:
> You can't put 100,000 of anything into the Push Notification payload. You COULD fit close to 240 1-byte identifiers into one payload, fewer for 2-byte identifiers, fewer still for 4-byte identifiers.
>
> Really, your app should directly query your server to get the updated info for 100,000 users; doing so in response to a Push Notification or when the user launches your app and there hasn't been a Push Notification lately.
>
> "Each push notification carries with it a payload. The payload specifies how users are to be alerted to the data waiting to be downloaded to the client application. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit. Remember that delivery of notifications is “best effort” and is not guaranteed."
>
> --
> C. Keith Ray
> twitter: @ckeithray
> phone: 650-KEY-4RAY
>        650-539-4729http://agilesolutionspace.blogspot.com/

Bagusflyer

unread,
Mar 9, 2012, 9:24:34 PM3/9/12
to meticulo, Easy APNs
No, you have to send 100,000 messages. This is what I'm currently doing. But it's very inefficient. Because it seems I can only send about 70-80 messages per minute. That means it takes about 20 hours to send all messages out for all 100,000 users.

Somebody suggest to combine multiple messages into one packet. The idea is to compile multiple ,for example, 200 payloads (maximum size of a payload is 256 bytes) into one big packet then send them out. In this way, to send out all 100,000 messages, you can take only about less than 10 minutes ( theoretically ) to send out all messages.

But I haven't tried this method because there is one problem for me in this way. I'll check the feedback when I send out one message so that I know whether the message is sent out successfully and whether the device token is still valid. If it's not valid anymore(maybe user uninstall your app already), I'll delete it from my database. But if I use above mentioned method, I don't know how to check the feed back.

Yossi Cohen

unread,
Mar 10, 2012, 3:18:56 PM3/10/12
to easy...@googlegroups.com
Just think that urban airship got something called debug flag

If it check that push send more slow (they check apple response) , if it is not check than it sends 100 times faster
(guess they might not checking response)

Any way i will be happy if someone have easy apn modified php code to send multiple token in one message , since I'm also handling 60,000 tokens and it will take many hours to send broadcast

Guillaume

unread,
Mar 14, 2012, 9:33:18 AM3/14/12
to Easy APNs
I have 90,000+ tokens so I will also be interested in an easy apns
modified php code !! :))



On 10 mar, 21:18, Yossi Cohen <yossi.c...@gmail.com> wrote:
> Just think that urban airship got something called debug flag
>
> If it check that push send more slow (they check apple response) , if it is not check than it sends 100 times faster
> (guess they might not checking response)
>
> Any way i will be happy if someone have easy apn modified php code to send multiple token in one message , since I'm also handling 60,000 tokens and it will take many hours to send broadcast
>
> ...
>
> plus de détails »

iTarek

unread,
Sep 25, 2012, 10:01:38 AM9/25/12
to easy...@googlegroups.com
Ok here is the best solution...

Make sure you have the last version of EASYAPNS

With this version the limit is 100 and it waits 1 sec for apple response to make sure the push is ok...
SO 100 push takes about 110 sec to send, and if you set the limit for more than 100 your server will not respond and you will get timeout

To fix that just edit the class_APNS.php
change those lines
$tv_sec = 0;
$tv_usec = 200000; // Timeout. 1 million micro seconds = 1 second 

And now you can set the limit up to 10000

Hope this help you out 
Reply all
Reply to author
Forward
0 new messages