private static function getScriptDir()
{
static $result;
if (null === $result) {
$script = $_SERVER['SCRIPT_NAME'];
if (is_link($script)) {
$linkTarget = readlink($script);
// If the link target is relative to the link
if (false === realpath($linkTarget)) {
$linkTarget = dirname($script) . '/' . $linkTarget;
}
$script = $linkTarget;
}
$result = dirname($script);
}
return $result;
}