this should work,
function realpath_constant_time(string $path, float $target_seconds, bool &$constant_time_success = null){
$start_time=microtime(true);
$ret=realpath($path);
$constant_time_success = @time_sleep_until($start_time+$target_seconds);
return $ret;
}
for example, a realtime that always uses exactly 1 millisecond (should be more than enough for SSD-based servers, perhaps rotating harddrive based servers may need something closer to 10 milliseconds, i don't know):
realpath_constant_time("/path/to/../to/file.txt",0.001,$constant_time_success);
and you can use $constant_time_success to check if it was actually constant-time, or if you needed to set a higher value..