Optimize this path location script?
A different way:

preg_match(':^/[^/]*/[^/]*/:', realpath(__DIR__), $matches);
$realPath = $matches[0];


This matches the first and second files in path, and stores them in $matches.