downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

pcntl_exec> <PCNTL 関数
[edit] Last updated: Fri, 25 May 2012

view this page in

pcntl_alarm

(PHP 4 >= 4.3.0, PHP 5)

pcntl_alarmシグナルを送信するアラームを設定する

説明

int pcntl_alarm ( int $seconds )

プロセスに対して、 指定した秒数後に SIGALRM シグナルを送信するタイマーを作成します。 pcntl_alarm() をコールすると、 それまでに設定されていたアラームはすべて取り消されます。

パラメータ

seconds

待機する秒数。seconds がゼロの場合は、 新しいアラームは作成されません。

返り値

それまでに予定されていたアラームの予定時刻までの秒数を返します。 事前に予定されていたアラームがなかった場合には 0 を返します。



add a note add a note User Contributed Notes pcntl_alarm
thessoro at gmail dot com 20-Apr-2011 09:05
If your process uses SIGALRM and sleep() at the same time, the alarm set could make sleep() to return prematurely.

To avoid this and ensure your process waits a number of seconds you could use a function or class similar to this one:

<?php
class SleepWorkaroundForSIGALRM {
    private
$time;
    function
__construct($seconds) {
       
$this->time = time() + $seconds;
        while (
$this->time >= time()) {
           
sleep(1);
        }
    }   
?>
j at ukr-info dot net 20-Oct-2005 04:51
<?php
   
declare(ticks = 1);

    function
signal_handler($signal) {
        print
"Caught SIGALRM\n";
       
pcntl_alarm(5);
    }

   
pcntl_signal(SIGALRM, "signal_handler", true);
   
pcntl_alarm(5);

    for(;;) {
    }

?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites