ignore_user_abort
ignore_user_abort(?bool $enable = null): int
Read/set the "keep running after client abort" switch: null reads the current value, a bool sets it and returns the previous one (int 0/1); pairs with connection_status' bitmask — the status tells you whether the client left, this switch decides whether you keep going; CLI has no client, so get/set is pure switch read/write.
C C23
/* the "keep going after the peer died" switch in C is SIGPIPE handling:
ignore it and writes to a dead socket return EPIPE instead of killing us */
#include <signal.h>
#include <stdio.h>
int main(void) {
void (*previous)(int) = signal(SIGPIPE, SIG_IGN); /* set; returns the old handler */
printf("%d\n", signal(SIGPIPE, SIG_IGN) == SIG_IGN); /* readback: our setting */
signal(SIGPIPE, previous); /* restore: no residue */
return 0;
}
1
C++ C++26
#include <csignal>
#include <iostream>
// same as C: SIGPIPE ignoring is the keep-writing-after-disconnect switch
int main() {
void (*previous)(int) = std::signal(SIGPIPE, SIG_IGN); /* set; old handler back */
std::cout << (std::signal(SIGPIPE, SIG_IGN) == SIG_IGN) << "\n"; /* readback */
std::signal(SIGPIPE, previous); /* restore */
return 0;
}
1
C# v11.0.100
using System;
// no client-abort switch: ASP.NET owns the connection (RequestAborted token
// is the abort signal); try/finally is the std keep-going guarantee
bool[] ran = { false, false };
try {
ran[0] = true; // the work
} finally {
ran[1] = true; // finish what you started
}
Console.WriteLine(ran[0] && ran[1]);
True
Go v1.27.4
package main
import (
"context"
"fmt"
)
// Go's server idiom is the reverse default: a request carries a ctx whose
// Done() fires on client abort - you opt in to "give up", not to "keep going"
func main() {
ctx := context.Background() // a real request would carry its own ctx
fmt.Println(ctx.Err() == nil) // alive: the ignore_user_abort(true) side
}
true
Java v27.0.1
public class Main {
public static void main(String[] args) {
// no client-abort switch: servlet containers own the connection;
// the std guarantee closest in spirit is try/finally - cleanup runs
boolean[] ran = {false, false};
try {
ran[0] = true; // the work
} finally {
ran[1] = true; // finish what you started
}
System.out.println(ran[0] && ran[1]);
}
}
true
JavaScript v26.13.1
// Node: the request's "close"/abort events are the disconnect signal;
// the std keep-going guarantee is try/finally around the work
const ran = [];
try {
ran.push("work");
} finally {
ran.push("cleanup"); // finish what you started
}
console.log(ran.join(","));
work,cleanup
PHP v8.6.0
// ignore_user_abort(?bool $enable): int - read/set the "keep running
// after client abort" switch; returns the PREVIOUS value (int). CLI has no
// client (connection_status owns the state bitmask side)
$initial = ignore_user_abort(); // read: 0 = abort kills, 1 = keep going
var_dump($initial === 0 || $initial === 1); // derived fact: the value is a binary switch
$previous = ignore_user_abort(true); // set true, returns the previous value
var_dump($previous === $initial); // get/set roundtrip: the old value comes back
var_dump(ignore_user_abort()); // int(1): the switch is now on
ignore_user_abort(false); // restore the initial state - no global residue
var_dump(ignore_user_abort() === $initial); // restored
bool(true) bool(true) int(1) bool(true)
Python v3.15.2
# no client-abort switch: a Python script owns its lifecycle end to end -
# the std guarantee closest in spirit is try/finally: cleanup runs no matter
# how the block exits (web frameworks kill workers; task queues go async)
ran = []
try:
ran.append("work")
finally:
ran.append("cleanup") # finish what you started - ignore_user_abort's spirit
print(ran == ["work", "cleanup"])
True
Rust v1.99.1
// std has no disconnect signal; the honest shape demo: a static AtomicBool
// with get/set/restore - the ignore_user_abort switch in miniature
use std::sync::atomic::{AtomicBool, Ordering};
static KEEP_GOING: AtomicBool = AtomicBool::new(false);
fn main() {
let previous = KEEP_GOING.swap(true, Ordering::SeqCst); // get-and-set
println!("{}", !previous); // the default was off
println!("{}", KEEP_GOING.load(Ordering::SeqCst)); // now on
KEEP_GOING.store(false, Ordering::SeqCst); // restore: no residue
println!("{}", !KEEP_GOING.load(Ordering::SeqCst));
}
true true true
TypeScript v26.13.1
// Node: the request's "close"/abort events are the disconnect signal;
// the std keep-going guarantee is try/finally around the work
const ran: string[] = [];
try {
ran.push("work");
} finally {
ran.push("cleanup"); // finish what you started
}
console.log(ran.join(","));
work,cleanup
Language differences
Status vs switch: the existing connection_status entry (A38) reads back "is it disconnected now" (a bitmask), this entry decides "keep running after the disconnect" (PHP's request loop consults this switch) — together they form the complete disconnect semantics; the deterministic assertions use a get/set roundtrip: the initial value is always 0/1, the value returned by set matches the initial read, reading right after set(true) is always 1, and after restore it matches the initial read — environment-independent throughout (no assumption whether the initial value is 0 or 1).
PHP: ignore_user_abort(null) reads, ignore_user_abort(true/false) sets and returns the previous value (int); default 0 (a client abort terminates the script); CLI has no client connection, so the switch is just ini state being read and written (the matching ini directive is ignore_user_abort, readable via ini_get); pair with connection_aborted() to poll "is the client still there" inside long tasks.
Python: no such switch — the script owns its lifecycle end to end, and "client disconnect" is a framework-level event (WSGI/ASGI disconnect); background work uses threads, task queues (celery etc.), or custom signal handling; try/finally is the std "finish no matter what" guarantee.
Go: the server idiom is the reverse of PHP's default — request.Context()'s Done() closes on client abort, and the code explicitly selects to give up; "keep going" means ignoring the ctx (or deriving with context.WithoutCancel). context.Background() demonstrates the no-abort side.
Java: the servlet container owns the connection and the standard API has no switch; async work uses thread pools / CompletableFuture; try/finally is likewise the semantically closest std guarantee.
C#: ASP.NET's HttpContext.RequestAborted (a CancellationToken) is the abort signal — same semantics as Go's ctx (default: give up); "keep going" = ignore the token or finish on a background thread.
JavaScript/TypeScript: Node's request.on("close")/AbortSignal is the disconnect signal; work that must finish before the process dies belongs in a process-level queue or process.on("beforeExit").
C/C++: no request-level switch — the real "keep writing after the peer died" switch is signal(SIGPIPE, SIG_IGN): without it the first write to a dead socket kills the process; with it, write returns -1/EPIPE and the code decides what next; the example performs set/readback/restore, matching PHP's get/set/restore shape.
Rust: std has no disconnect signal; real-world analogs are signal-hook/tokio::signal (Unix signals) or framework-level; the example reproduces the get/set/restore shape with a static AtomicBool (swap returns the previous value — isomorphic to the PHP signature).