SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36
  1. #26
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. So it is going to work in the normal environment.
    Last edited by ArunB; Sep 22, 2008 at 02:17.

  2. #27
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Now my PHP is not running as CGI and I am using:
    PHP Code:
    header'HTTP/1.1 202 Accepted' );
    header'Connection: Close' );
    header'Content-Length: 0' );
    flush();
    echo 
    'After flush...'
    But no use. Still getting "After flush..." in response.

  3. #28
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ArunB View Post
    Now my PHP is not running as CGI and I am using ...
    And which environment is it running in now, then?

  4. #29
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Windows XP + PHP 5.2.6 + Apache 2.2.8

  5. #30
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try with this?

  6. #31
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Did you try with this?
    Yes,
    Output is: Should see thisShouldn't see this

  7. #32
    ::==:: Bonzo_CS's Avatar
    Join Date
    Dec 2003
    Location
    (Cardiff Wales)
    Posts
    747
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did anyone manage to find the solution to this ? I am having the same problem where my ajax script hits a lengthy process and need to send a response before it completes.

    Tried the solution above, but no joy.

  8. #33
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since I am about to need the same functionality in my app ( albeit .net) I've thought that that easiest way (at least from a point of view) is like this:

    1. One request starts the time consuming action (via ajax) and stores temporary results, statuses in a common (maybe session) place.

    1.a The request should set a flag of operation started and return if the flag is already set.

    2. From the browser another ajax request is fired from time to time to check the results until the action is completed.

    I haven't tested it yet but I will these days.

  9. #34
    ::==:: Bonzo_CS's Avatar
    Join Date
    Dec 2003
    Location
    (Cardiff Wales)
    Posts
    747
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I have managed to sort of get a close solution to what kyberfabrikken suggested using the flush and headers.

    header('HTTP/1.1 202 Accepted');
    header('Content-Length: 0');
    header('Connection: Close');

    echo $Services_JSON->encode($success);

    flush();

    $Class->function($id);
    This actually responds to the caller and the code after the flush runs. My only problem now is that I am not getting the JSON response from the echo, which is probably to do with the Content-Length being 0. If I change this value to anything but 0, I get a JSON response, but it hangs again.

    Praetor, your solution would work well and I would go for that, but I can't rely on the second request in my script as I have to have a series of responses and checks. For instance if a second request is made I already run a check to see if the script is running for that user. However if it wasn't for that it's a good idea, cheers.

  10. #35
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Finally, this script is working.

    PHP Code:
    <?php
    header
    'HTTP/1.1 202 Accepted' ); 
    header'Connection: Close' ); 
    header'Content-Length: 0' ); 
    flush(); 
    echo 
    'After flush...'
    for( 
    $i 0$i 88900000$i++ )
    {
        echo 
    $i;
    }
    If I remove the

    PHP Code:
    header'Content-Length: 0' ); 
    then I am getting maximum execution time error (because script is running for more than thirty seconds).

    If I use it, no error and nothing is loading.

    I think that this is working.

  11. #36
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    This code is working in Windows XP SP2 + Apache 2.2.8 + PHP 5.2.6 environment.

    But this is not working in CentOS 5 + Apache 2.2.8 + PHP 5.2.6 environment.

    Can some body help regarding this?


Tags for this Thread

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
  •