What are the best practices for efficiently defining the root path in PHP scripts?

When defining the root path in PHP scripts, it is important to ensure that the path is consistent across different environments and platforms. One efficient way to define the root path is by using the $_SERVER['DOCUMENT_ROOT'] variable, which provides the absolute path to the document root directory of the server. This ensures that the path is always accurate and reliable.

$root_path = $_SERVER['DOCUMENT_ROOT'];