1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is it possible to return status to client in between the execution of php script

Discussion in 'PHP' started by indi.anupam, Feb 28, 2009.

  1. #1
    Is it possible to return status to client in between the execution of php script?

    I was actually automating the blog posting mechanism for my website and was writing a script which pick the agents data from database and post blog (in a predefined format) to my website. The problem is that when it is posting blogs (often >500 / attempt) there is no status report so that I can know what the script has done in a particular movement of execution.

    All I have to do is wait until the script finish posting and send a report mail to me with details!

    -Anupam
     
    indi.anupam, Feb 28, 2009 IP
  2. ergtron

    ergtron Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can't do it realtime with php. But I guess you can find a workaround. Create an extra table in your database to store the post count, and set your php script to update that table with each successful post.
    Then you can pull that data in another page so that everytime you refresh that page the number will update.
     
    ergtron, Feb 28, 2009 IP
    indi.anupam likes this.
  3. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, like this:
    
    echo 'Status message.';
    flush();
    ob_flush();
    
    PHP:
    Will display whatever you echo'd to the client while keeping the client connected and the script will continue executing. This can be a pretty powerful ability when you consider that you can use it to output javascript.
     
    Shoro, Feb 28, 2009 IP
    indi.anupam likes this.
  4. indi.anupam

    indi.anupam Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the expert advice :)

    Both the solutions were awesome..

    The idea for flushing the out was very good and it worked in the way I wanted. Thank you Shoro..


    Also I used the idea to store the status in a DB table and let another script display the status by mixing some Ajax and it gave me a look like a progress bar. Your idea was gr8 ergtron :rolleyes:

    Thank you guys. It was better then I thought..:D
     
    indi.anupam, Mar 1, 2009 IP