SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX - Handling expensive (slow) requests

    I have an application that allows users to fire off an expensive request (10 - 30 seconds).

    The idea I have is to fork the request into a queuemanager that will return success once the task is done.

    As always the aim is for something that uses as little web server cpu as possible, but keeps the user informed of progress. It doesn't have to be a progress bar, just a little animated activity image that closes once the job is done.

    Ideally I wouldn't have the client connection open during the whole thing as the server can use that process to server other pages. Are there any clever solutions for this kind thing out there?

  2. #2
    SitePoint Addict ChiefLee's Avatar
    Join Date
    Apr 2009
    Location
    Lawrence KS
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you get the initial request, you can load a queue. This can be as simple as a database entry in a table called "jobs" with a status of 0 (incomplete). The user then needs to be sent a response, so the AJAX response contains the id of the job in the database. When the browser gets the id of the job, you can have it post back to the server every 5 or so seconds to check the status of the job. Meanwhile, your server is running a cron job or a forked process to process the job (select all jobs where status is 0, and run the process method on each) marking the status as 1 (complete) when it finishes. After the status is set to 1, your script will generate a message telling your user that the process is complete.
    Add your logo to Pocket Folders.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •