home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / asp / register_cleanup.asp < prev    next >
Encoding:
Text File  |  2003-09-03  |  1.3 KB  |  41 lines

  1. #!/usr/bin/perl /usr/bin/asp-perl
  2.  
  3. <!--#include file=header.inc-->
  4.  
  5. <% my $Sleep = 3; %>
  6. We are about to sleep for <%=$Sleep %> seconds.  Before that, 
  7. this script registers a routine to be executed after this script 
  8. finishes, which will increment a count.  This count displayed after 
  9. these <%=$Sleep %> seconds if you do nothing.
  10. <p>
  11. Try this.  Hit reload, then your browser <b>STOP</b> button quickly.  
  12. Do this repeatedly.  Then let the script execute normally.  You will 
  13. see the registered code executed appropriately.  
  14. <p>
  15. Up through Apache version 1.3.4, this method is important, because mod_perl 
  16. halts script execution immediately when the user hits a STOP button, 
  17. so doing $Server->RegisterCleanup is the only way to consistently
  18. execute code that you have to for that script.
  19. <p>
  20. sleeping for <%=$Sleep %> seconds...
  21. <p>
  22. <%    
  23. $Response->Flush();
  24. $Server->RegisterCleanup( sub { $main::Session->{cleanup_count}++ }); 
  25. for(1..$Sleep) {
  26.     print 'sleeping 1 second...<br>';
  27.     $Response->Flush();
  28.     if(! $Response->{IsClientConnected}) {
  29.     $Response->Debug("ending script execution since client is no longer connected");
  30.     $Response->End;
  31.     }
  32.     sleep(1);
  33. }
  34. %>
  35. <p>
  36. Count incremented in $Server-<%=$Server->HTMLEncode('>')%>RegisterCleanup 
  37. <b><%=$Session->{cleanup_count} || 0 %></b>
  38.  
  39. <!--#include file=footer.inc-->
  40.  
  41.