note 60119 added to function.pcntl-signal
| From: | erik at phpcastle dot com | Date: | Tue, 27 Dec 2005 11:46:19 +0000 |
| Subject: | note 60119 added to function.pcntl-signal | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100777@lists.php.net to get a copy of this message | ||
When you want to stop a CLI script by a keyboard interupt then you should use SIGINT.
Example script:
#!/usr/bin/php5
<?php
// tick use required as of PHP 4.3.0
declare(ticks = 1);
// signal handler function
function sig_handler($signo)
{
switch ($signo) {
case SIGINT:
// handle shutdown tasks
echo "Keyboard pressed...\n";
exit;
break;
default:
// handle all other signals
}
}
echo "Installing signal handler...\n";
// setup signal handlers
pcntl_signal(SIGINT, "sig_handler");
// or use an object, available as of PHP 4.3.0
// pcntl_signal(SIGUSR1, array($obj, "do_something");
// Just a stupid simple loop
for ($i = 1; $i <= 10; $i++){
echo ".";
sleep(1);
}
echo "Done\n"
?>
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-signal.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60119
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60119&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60119&report=yes
Search -- http://master.php.net/manage/user-notes.php