Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
    
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? –  N.B. Nov 25 '11 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 Nov 25 '11 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 Nov 26 '11 at 19:08

3 Answers 3

up vote 0 down vote accepted

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.

share|improve this answer
    
Awesome - Never used Ruby before, but already I'm loving it :) –  Tom Irving Jan 12 '12 at 18:19
    
Ruby isn't more scalable than PHP... –  Florian Margaine Aug 13 '13 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 Aug 13 '13 at 14:36

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.

share|improve this answer

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.

share|improve this answer
    
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 Nov 25 '11 at 20:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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