To the official PHP view this function description
Pcntl_alarm (PHP 4 >= 4.3.0, PHP 5)
pcntl_alarm-set a alarm alarm signal for the process
Description ¶int pcntl_alarm (int $seconds)
Creates a timer that sends a SIGALRM signal to the process after the specified number of seconds. Each call to Pcntl_alarm () cancels the previously set alarm signal.
Parameter ¶seconds the number of seconds to wait. If the seconds is set to 0, the alarm signal will not be created.
The return value ¶ Returns the number of seconds remaining in the last alarm dispatch (from the alarm signal), or 0 when there is no alarm schedule (or previous dispatch completed).
Instance
| The code is as follows |
Copy Code |
|
<?php
DECLARE (ticks = 1);
function A ()
{
Sleep (10);
echo "a Finishin";
}
Function B ()
{
echo "STOPN";
}
Function C ()
{
Usleep (100000);
}
function sig ()
{
throw new Exception;
}
Try
{
Set an alarm signal to be executed once a second
Pcntl_alarm (1);
Install alarm signal, and bind callback
Pcntl_signal (SIGALRM, "sig");
A ();
Cancel the alarm signal.
Pcntl_alarm (0);
}
catch (Exception $e)
{
echo "Timeoutn";
}
b ();
A ();
b (); |
attached, PCNTL extended installation
PCNTL extensions can support multithreaded operations in PHP.
The original need to recompile PHP back configrue hint plus--enable-pcntl
In order to save trouble directly compiled bird.
| The code is as follows |
Copy Code |
# Cd/usr/local/src/php-5.2.6/ext/pcntl
# phpize
#./configure--with-php-config=/usr/local/php/bin/php-config
# Make && make install
|
pcntl.so Add to PHP.ini OK