Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Guys,
    In my CMS, I edit and generate a whole ton of stuff and then PRINT it. In some cases, though, I want to do something slow like sending an email from the script after the entire page has PRINTed.

    This works fine... but the user sees the page keep "loading" (though nothing happens) while the script finishes.

    How can I kill the connection and tell the browser "I'm Done" from the script?
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    You can tell PHP to exit(); the script. I am not sure entirely what you are trying to achieve, but something like

    PHP Code:
    <?php

    print $var1;
    print 
    $var2;
    // so on & so forth, end of printing variables
    exit();

    ?>
    Again not sure if that will help but hope it does!

  4. #3
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Quote Originally Posted by bfsog
    You can tell PHP to exit(); the script.
    Hey, thanks, but die() is not what I had in mind. (It's an alias.)

    I want to continue execution of the script, but kill the connection to the user. So tell the browser to stop listening, but keep running the script.
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  5. #4
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    I may have found it:
    PHP Code:
    header('Connection: close'); 
    I'll let you know if this works.
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  6. #5
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Hmm... Doesn't seem to work.
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  7. #6
    Member
    Join Date
    Jul 2005
    Posts
    39
    Member #
    10659
    Maybe you should try an AJAX solution to trigger the sending of the e-mail via a separate script after the page has loaded. This way the script executes in the background without the user noticing.

  8. #7
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Quote Originally Posted by T1Oracle
    Maybe you should try an AJAX solution to trigger the sending of the e-mail via a separate script after the page has loaded. This way the script executes in the background without the user noticing.
    Good idea... The only problem is I want this script executed regardless of whether the user:
    - hits the STOP button
    - has turned off JS
    - has a browser that doesn't support XMLHttpRequest
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.

  9. #8
    Member
    Join Date
    Jul 2005
    Posts
    39
    Member #
    10659
    You could add a link for those users that opens in a new window (target="_blank") or somewhere else. Or you have it set up so those with javascript and AJAX support get the AJAX enabled page and everyone else just has to see extra loading.

    Hmm, after googling: php close http connection
    I found this: http://www.codecomments.com/archive2...-7-245417.html
    And more importantly, this: http://us3.php.net/flush

    Hopefully that helps.

  10. #9
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    You're looking for output buffering.

    Check out ob_start() and ob_flush().
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  11. #10
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    ob_* and flush() are not what I want; the output is printing just fine. The user sees the page, but then the throbber will keep moving & the page acts as if it's loading while any additional scripts execute.

    I actually want to close the connection to the client.

    If this is not possible, then I'll have to somehow (as suggested in T1Oracle's link to codecomments.com) log what I want done, when possible, and execute it via another script. Somehow. Chronjob or something else I've never done (but am willing to learn).

    Similarly, a link for the user to click or an AJAX solution is not what I want. The whole thing should be 100% client-side and 100% transparent to the user. (Though in the future, for certain things, I may use AJAX to check on the progress of such post-PRINT activities, but *only* in certain cases like sending a newsletter.)


    Is there a way for my PHP script to call another script? To be acceptable, my PHP script wouldn't have to wait for the other script to terminate!
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:29 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com