Dynamic updating text and background running task

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cappamontana
    New Member
    • Sep 2007
    • 21

    #1

    Dynamic updating text and background running task

    Hi,
    I was wondering if somebody knows a simple way to update a (status) text in PHP without refressing. The situation is as follows;
    I have a class that scrawls a domain and gathers the keyword denstity of a certain page within that domain. Now I want to show the user what the status is of the task (in %). Maybe I can use ob_flush() or flush() in combination with IFRAMES, but I prefer to don't. The problem with AJAX for as far as I know is that it won't accept flush and you cant make it holding a connection online (readystate -it just accepts status 3/4-).
    On the otherside I also want the script to run on the background. So the user can still surf on the website while the script is generating. When the script is ready it should attent the user (with a popup or something).
    I can do that by listening to a socket till the script is done but I dont know if that is the best way.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    I suppose this is possible by using Javascript. (It won't be pretty tho :P)

    You could, for example, create a <div> or <span> at the top, naming it something like 'progress', and have PHP echo a Javascript snipped at certain intervals, changing the contents of the 'progress' container.

    Somewhat like:
    [code=php]
    <pre>
    <span id="progress">0 </span>% complete
    </pre>

    <?php
    ob_start();
    while($somethin g)
    {
    # Do something...

    $percentComplet e++;
    echo "\n
    <script type=\"text/javascript\">
    document.getEle mentByID('progr ess').innerHTML = '{$percentCompl ete}';
    </script>";
    ob_flush();
    flush();
    }
    ?>
    [/code]

    Comment

    • Cappamontana
      New Member
      • Sep 2007
      • 21

      #3
      Hi Atli,

      Sorry I was out for a while...I'am familiar with the javascript way,I jus't didn't know it was the proper way to do it.
      Thanks anyway... :D

      p.s You have an idea about the background running task?

      Comment

      Working...