Can someone point me in the correct direction for researching how to prevent users from breaking out of a php script with Ctrl+Z, Ctrl+C?
ctrl c is used to kill a process. It terminates your program. ctrl z is used to pause the process. It will not terminate your program, it will keep your program in background.
Turned out the way Ctrl-c works is quite simple — it's just a shortcut key for sending the interrupt (terminate) signal SIGINT to the current process running in the foreground. Once the process gets that signal, it's terminating itself and returns the user to the shell prompt.
If you have php compiled with PCNTL (Process Control) and are not running Windows you can use pcntl_signal()
.
There is an example here which I modified, and it seems to catch Ctrl-C ok:
<?php
declare(ticks = 1);
pcntl_signal(SIGINT, "signal_handler");
function signal_handler($signal) {
switch($signal) {
case SIGINT:
print "Ctrl C\n";
}
}
while(1) {
}
If you try to install a handler for SIGSTP
nothing happens, but I don't know why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With