首页 > 代码库 > PHP如何为函数执行设置超时

PHP如何为函数执行设置超时

<?phpdeclare(ticks = 1);function a(){    sleep(10);    echo "a finishi\n";}function b(){    echo "Stop\n";}function c(){    usleep(100000);}function sig(){    throw new Exception;}try{    pcntl_alarm(1);    pcntl_signal(SIGALRM, "sig");    a();    pcntl_alarm(0);}catch(Exception $e){    echo "timeout\n";}b();a();b();

PHP如何为函数执行设置超时