SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast DaveCheney's Avatar
    Join Date
    Dec 2003
    Location
    Melbourne, Australia
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Terminate output from PHP

    Hi,

    I'd like to write a script that finishes its output, so that the little logo in the browser stops spinning, but continues to be available to do work.

    Is register_shutdown_function a good idea? I tried messing with at a little but it seamed that the number of things I could do there were limited, ie no output (duh!, no biggie) but also I could not do any file i/o.

    Code:
    <?php
    
    	// minion
    	
    register_shutdown_function('main');
    exit();
    
    function main()
    {
    	$fd = fopen('output.txt','a');
    	while(1)
    	{
    		fputs($fd,time()." minion running\n");
    		sleep(2);
    	}
    }
    
    ?>
    Did not work as expected, ie output.txt was being updated.

    Cheers

    Dave

  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveCheney
    Hi,

    I'd like to write a script that finishes its output, so that the little logo in the browser stops spinning, but continues to be available to do work.
    if i understand you correctly, then the answer is that it can't be done. the throbber (little logo) will keep throbbing for as long as the connection is open and the webserver is sending data. once it stops, the connection for that particular request has been closed and the server has no other way of sending any more data to the browser.
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thinking about it once more, i think i now understand what you meant. effectively you'd want the PHP to trigger an external program, running as a separate process. you could just have your page use something like the system function http://uk.php.net/manual/en/function.system.php to trigger another PHP file from the command line...if that makes sense.
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  4. #4
    SitePoint Enthusiast DaveCheney's Avatar
    Join Date
    Dec 2003
    Location
    Melbourne, Australia
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes - I would like to in fact start a daemon process. Ideally i would like the process to close the connection itself so the throbber (nice name, mind if I use it?) will indicate that the connection is finished, but if not I can always handle closeing the browser (so long as it doesn't close my app)

    For various reasons, windows laptop, non dedicated hosting, system/exec/pcntl aren't available to me.

    Cheers

    Dave

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so long as it doesn't close my app
    ignore_user_abort would help you with that.

  6. #6
    SitePoint Enthusiast DaveCheney's Avatar
    Join Date
    Dec 2003
    Location
    Melbourne, Australia
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gaheris
    ignore_user_abort would help you with that.
    It seams the only way to terminate the output of a script, is the terminate the script. Which makes sense, regardless if php is CGI or an apache module it is still treated like a series of events. Apache may be able to forward the stdout of the php process but until that file descriptor closes, apache will keep the connection to the browser open.

    In another thread I wrote this http://www.sitepointforums.com/showt...47#post1058847 to run a background task while terminating the calling script.

    From my small experiments with register_shutdown_function() it seams they are very limited in what they can do. Ie, no output(duh), but no file i/o either . Has anyone got some pointers to using register_shutdown_function()?

    Cheers

    Dave


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
  •