Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable ctrl-z, ctrl-c from breaking out of a php script

Tags:

php

signals

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?

like image 938
teksolo Avatar asked May 05 '10 14:05

teksolo


People also ask

How do you stop a Ctrl Z process in Linux?

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.

What process can be terminated by typing Ctrl-c from the keyboard?

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.


1 Answers

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.

like image 133
Tom Haigh Avatar answered Sep 29 '22 16:09

Tom Haigh