Update page using Ajax while PHP script is running

Posted on 2007-07-20
Last Modified: 2008-01-09
I am using PHP to parse XML data, which ultimately gets stored into a database. However, while I am downloading and parsing the XML (which takes about 30 seconds), I would like to give the user status reports.

Since I am on Apache 1.0.33, I cannot do any type of page flushing to force output to the browser.

What I would like is to use Ajax to update the status div element while my script is running.

The only solution I have in mind is to use 2 hidden iframes. 1 frame holds the actual script that parses data, and stores messages in a $_SESSION and a second script that reloads (using javascript) every second or so, reads the contents of the $_SESSION message and updates the form.

However, this does not seem to be a very elegant solution. I guess I want more of a event-driven solution.
Question by:darklandsinc
    1 Comment
    LVL 4

    Accepted Solution

    You could just take your own solution of using iframes and two scripts and do it with AJAX instead of the iframes.

    Call the script that parses the XML through xmlhttprequest, then call another script with xmlhttprequest to constantly output the value of a certain session variable, using the output of the second script to fill a div.

    Update the value of the session variable as often as you can within the xml parsing script to give your users more of an idea of whats going on.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    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…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now