PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

pack> <highlight_string
Last updated: Fri, 10 Oct 2008

view this page in

ignore_user_abort

(PHP 4, PHP 5)

ignore_user_abortクライアントの接続が切断された際にスクリプトの実行を終了するかどうかを設定する

説明

int ignore_user_abort ([ bool $setting ] )

クライアントの接続が切断された際にスクリプトの実行を終了するかどうかを設定します。

パラメータ

setting

省略した場合は、この関数は単に現在の設定を返します。

返り値

以前の設定を表す boolean 値を返します。

注意

PHP は、クライアントに情報が返ってくるまでは ユーザが切断しようとしたかどうかを検出できません。 単に echo 文を使っただけでは、情報が送信されたかどうかを保証できません。 flush() を参照ください。

参考



pack> <highlight_string
Last updated: Fri, 10 Oct 2008
 
add a note add a note User Contributed Notes
ignore_user_abort
adrian
26-Apr-2007 06:37
In the last example the call to ignore_user_abort() is used incorrectly.  The manual clearly states that is the first parameter is not given, only the value is returned!

Specify a boolean value like this,

ignore_user_abort(TRUE);
spiritual-coder at spiritual-coder dot com
14-Jul-2006 12:45
If you want to simulate a crontask you must call this script once and it will keep running forever (during server uptime) in the background while "doing something" every specified seconds (= $interval):

<?php
ignore_user_abort
(); // run script in background
set_time_limit(0); // run script forever
$interval=60*15; // do every 15 minutes...
do{
  
// add the script that has to be ran every 15 minutes here
   // ...
  
sleep($interval); // wait 15 minutes
}while(true);
?>
15-Dec-2005 04:44
"It will return the previous setting" -- not quite. It returns an int, not a bool (as per the syntax description)
Rustam
27-Jun-2005 07:57
I wrote a simple function that can "spawn" another thread within the webserver by making async http request. The page that is being spawned can call ignore_user_abort() and do whatever it wants in the background...

<?php

   
function http_spawn($page)
    {
       
$basepath=ereg_replace('[^/]*$', '', $_SERVER['PHP_SELF']);
       
$cbSock=fsockopen('localhost', $_SERVER['SERVER_PORT'], $errno, $errstr, 5);
        if (
$cbSock)
        {
           
fwrite($cbSock, "GET {$basepath}{$page} HTTP/1.0\r\n"
               
."Host: {$_SERVER['HTTP_HOST']}\r\n\r\n");
        }
    }
?>

Example:
<?php

   
if ($search_initialized)
       
http_spawn("ftindex.php");
?>
qartis at qartis dot com
06-Sep-2004 07:22
Note that the function name and description seem to be contradictory:

- ignore_user_abort  (TRUE, I want to ignore the user's abort request)
- Set whether a client disconnect should abort script execution (TRUE, I want to set this behavior)

The function name is the authoritative one: a value of TRUE will ignore the user's abort.
plamen at pulsator dot com
30-Mar-2001 01:21
The script should output something to the browser in order to abort. If there is no output the script keeps on running.

pack> <highlight_string
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites