1

I'm looking to add push notifications to one of my iOS apps. The app is a client for a website which doesn't offer push notifications.

What I've come up with so far:

  • App sends a message to home server when transitioning to background, asking the server to start polling the website for the logged in user.
  • The home server starts a new process to poll for that user. Polling happens every so many seconds / minutes.
  • When the user returns to the iOS app, the app sends a message to the home server to stop polling.
  • The home server kills the process polling for the user.
  • Repeat.

The problem is that this soon becomes stupid: 100s of users means 100s of different processes. It's just not scalable in the slighest.

What I've written so far is in PHP, using CURL to do the polling and I started with PHP a few days ago, so maybe I'm missing something obvious that could help me with this.

Some advice would be great.

3
  • Apache creates as many threads as there are users connected to Apache powered server. What's wrong with creating 100 processes for 100 connected users? What isn't scalable? Where do you think is the bottleneck? Are you looking for a single process that would have information about all the users that are connected?
    – Mjh
    Commented Nov 25, 2011 at 17:00
  • Every host I've looked at charges a lot more for this many processes. 100s of processes at one time quickly costs 100s of dollars/month.
    – Tom Irving
    Commented Nov 25, 2011 at 20:27
  • Ideally I'd like to open a few processes that can handle a whole load of users' profiles asynchronously, but I don't think PHP can do that.
    – Tom Irving
    Commented Nov 26, 2011 at 19:08

3 Answers 3

0

I don't think PHP is the way to go here, what your writing is backend code. I have written something very similar to this. I used ruby, eventmachine, em-http-request and beanstalkd. It worked well and was dead simple.

3
  • Awesome - Never used Ruby before, but already I'm loving it :)
    – Tom Irving
    Commented Jan 12, 2012 at 18:19
  • Ruby isn't more scalable than PHP... Commented Aug 13, 2013 at 14:33
  • 1
    I'm sure Ruby is great, but why is this the selected answer? What about Ruby is inherently more scalable than PHP or any other language you could have suggested to replace PHP?
    – svidgen
    Commented Aug 13, 2013 at 14:36
1

You might want to check out Comet or BOSH

Which are two methods to simulate sockets over HTTP, they are way more efficient than polling, and technically could scale to the 10k if you use a light weight server such as Nginx which is alot better at handling concurent connections than apache.

As for the server with more than 100 connections you could get a amazon EC2 micro server instance for something like 19$ /month that lets you run nginx and could scale a lot better than apache.

0

It sounds like you're using a short-polling algorithm. You could use a long-polling algorithm in order to only send information when the information that is being polled is updated. See the following: http://blog.samshull.com/2010/10/ajax-push-in-ios-safari-and-chrome-with.html

Also, why are you opening a separate process for each user? You should be able to send appropriate responses back to each user without opening extra apache processes.

1
  • I'm not sure I follow. I open a new process for each user because, as far as I'm aware PHP can't do asynchronous page retrievals..?
    – Tom Irving
    Commented Nov 25, 2011 at 20:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.