If you would like to calculatue the wall time of your script (includes all external DB/HTTP calls etc.) in Unix (in Windows this is already default behavior), you could use the following function:
<?php
$timeoutInSeconds = 3;
// This will make sure this is always called async
pcntl_async_signals(1);
// Second parameter is any callable (https://www.php.net/manual/en/language.types.callable.php)
pcntl_signal(SIGALRM, function() {
exit('Stop it!');
});
pcntl_alarm($timeoutInSeconds);
?>