echo something while working in background

Discussion in 'PHP' started by Fracisc, Nov 12, 2008.

  1. #1
    I was wondering how can I do this:

    add something to a database
    echo a dot
    add something else
    echo another dot

    .. but this in real time, not doing all and echo the dots after. I tried with a sleep() but doesn`t do what I need.

    Any ideas?
     
    Fracisc, Nov 12, 2008 IP
  2. iDemonix

    iDemonix Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you ran it from a command line then it'd work with echo, otherwise you'll probably want to look into something like Ajax, I'm not sure - is there any reason why you want to do this?
     
    iDemonix, Nov 12, 2008 IP
  3. dev_SeeInside

    dev_SeeInside Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use ob_flush();

    http://ca3.php.net/ob_flush

    
    // do your database insert
    echo ".";
    ob_flush();
    
    // do another insert
    echo ".";
    ob_flush();
    
    PHP:
     
    dev_SeeInside, Nov 12, 2008 IP
  4. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #4
    in pure php, you would have refresh the full page when you print a dot... the only way to do this would be by using ajax/javascript...
     
    daboss, Nov 12, 2008 IP
  5. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #5
    Use the function
    ob_implicit_flush(true);
    PHP:
    on the start of your script.

    Note, though, that some browsers (IE, for example) require some amount of html received to start displaying.
     
    wmtips, Nov 12, 2008 IP
  6. dev_SeeInside

    dev_SeeInside Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6

    Oh cool! I haven't used that one before! nice :)
     
    dev_SeeInside, Nov 12, 2008 IP