Pushing data from server to client ? Ajax / PHP ?

Posted on 2009-04-21
Last Modified: 2012-05-06
I am implementing an open connection that continually pushes data from server to client.

My initial thought was to include a frame of PHP sockets connecting to remote hosts that runs on a " while(true) " loop, then sends Javascript calls to the parent. Two problems with this is that the page is always loading so the icon is continually spinning, and that after a bunch of visitors connect to my site... I feel that it'll bog down with so many open connections. The first one doesn't seem like a big issue, more of an appearance thing... but the bogging down from too many persistent open connections seems like it will get really bad, really fast.

My second option was using Flash sockets to connect to remote hosts. That would take the payload off the server and put it on each client. This would be a great idea, but the remote hosts need to have a cross-domain-policy file in effect for me to connect to them ( which they won't ).

My third option is to run AJAX requests. This doesn't save me as much as I'd like because it would still have to run though my server... but I don't think it'd be as bad on my server as my first option of running the "while(true)" loop per each request. Problem with this is if the data comes in from server side... I'd have to wait til my next AJAX request to find out about it ( unless I can push it from the server? Is that possible? ) Second is that it would just be making a lot of requests.

Fourth option might be to run AJAX requests to a "while(true)" loop for 30-60 seconds at a time? I'm not sure if this would help any, but it seems like giving the PHP a break every so often might be better than letting it run constantly?

I guess my questions are:

  - How bad is running the persistent PHP data to the site? Even if it's not constantly receiving data.. sometimes just sleeping, but still running the process.

   - Is it possible to push data from the server to the client via AJAX so I don't have to wait 'til my next request to find out about it?

    - Is there a 5th option here that solves my problem?

The ideal solution would be the Flash sockets so I can pass the workload off to each individual user instead of having everyone channel through my server. I want to channel through like ICQ/GTalk, but they don't have cross-domain policies for me to use.

Anyone have some ideas?

Open in new window

Question by:MattKenefick
    LVL 3

    Accepted Solution

    LVL 4

    Author Comment

    Sounds like COMET is the way to go.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now