PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Rebel7284
Forum Newbie
Posts: 7 Joined: Mon Oct 20, 2008 2:59 pm
Post
by Rebel7284 » Mon Oct 20, 2008 3:11 pm
Hi,
I have a problem with signal handling not working in cli PHP
Relevant information:
PHP 4.3.11 (cli) (built: Jun 21 2005 12:10:12)
Cent OS kernel 2.6.9
Sample code:
Code: Select all
<?
pcntl_signal(SIGINT, "sighandler");
pcntl_signal(SIGQUIT, "sighandler");
function sighandler($signo){
echo "Got ", $signo;
//ob_end_flush();
}
while(1){
sleep(5);
}
?>
With this code running, I can press Ctrl-C and Ctrl-\ as much as I want, it ignores it and just sits there.
Does anyone have any idea what I'm doing wrong?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Oct 20, 2008 4:08 pm
You have to use ticks as well.
Code: Select all
<?
declare(ticks = 1);
pcntl_signal(SIGINT, "sighandler");
pcntl_signal(SIGQUIT, "sighandler");
function sighandler($signo){
echo "Got ", $signo;
//ob_end_flush();
}
while(1){
sleep(5);
}
?>
Rebel7284
Forum Newbie
Posts: 7 Joined: Mon Oct 20, 2008 2:59 pm
Post
by Rebel7284 » Mon Oct 20, 2008 4:37 pm
With ticks, the signals are not ignored. However, the sighandler function is not executed. The program terminates as if the signal handler was never set.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Oct 20, 2008 6:04 pm
Rebel7284 wrote: With ticks, the signals are not ignored. However, the sighandler function is not executed. The program terminates as if the signal handler was never set.
I tried that exact same code and it worked fine for me.
Code: Select all
<?
error_reporting(E_ALL);
ini_set("display_errors", 1);
declare(ticks = 1);
// ...
If you don't get any clues from running that post your PHP version.
Ah, he did already
Last edited by
requinix on Tue Oct 21, 2008 3:06 pm, edited 1 time in total.
Rebel7284
Forum Newbie
Posts: 7 Joined: Mon Oct 20, 2008 2:59 pm
Post
by Rebel7284 » Tue Oct 21, 2008 8:46 am
tasairis wrote:
I tried that exact same code and it worked fine for me.
Code: Select all
<?
error_reporting(E_ALL);
ini_set("display_errors", 1);
declare(ticks = 1);
// ...
If you don't get any clues from running that post your PHP version.
Tried it with those extra lines. No output whatsoever
Code: Select all
[dmitriyb@nydev_web ~]$ php test.php // Ctrl-C pressed here, seems to result in a newline and termination
[dmitriyb@nydev_web ~]$ php test.php // Ctrl-\ pressed here, results in 'Quit' and termination
Quit
[dmitriyb@nydev_web ~]$
I posted the PHP version in the first post
PHP 4.3.11 (cli) (built: Jun 21 2005 12:10:12)
Sadly updating is not an option, we have a ridiculous amount of legacy code.
This is driving me nuts.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Oct 21, 2008 3:14 pm
Wtf
Hmm... it was working with -f and not without, but now it works with both... Nevermind the above.
Last edited by
requinix on Tue Oct 21, 2008 5:00 pm, edited 1 time in total.
Rebel7284
Forum Newbie
Posts: 7 Joined: Mon Oct 20, 2008 2:59 pm
Post
by Rebel7284 » Tue Oct 21, 2008 3:38 pm
tasairis wrote: Wtf
Tried the -f option. Same behavior.
Syntac
Forum Contributor
Posts: 327 Joined: Sun Sep 14, 2008 7:59 pm
Post
by Syntac » Tue Oct 21, 2008 3:41 pm
Have you tried it with the -q option?
Rebel7284
Forum Newbie
Posts: 7 Joined: Mon Oct 20, 2008 2:59 pm
Post
by Rebel7284 » Tue Oct 21, 2008 4:01 pm
Syntac wrote: Have you tried it with the -q option?
I have now, no change in script's behavior
(don't know why it would make a difference though, doesn't -q _suppress_ warnings which I would want to see if there were any?)
Syntac
Forum Contributor
Posts: 327 Joined: Sun Sep 14, 2008 7:59 pm
Post
by Syntac » Tue Oct 21, 2008 5:32 pm
Er... Never mind. For a moment there I thought -q changed something to do with the execution mode.