PHP stream_resolve_include_path() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Stream

Definition

In PHP, stream_resolve_include_path() searches the include_path for a relative filename and returns the absolute path of the first match.

It answers "where would include or require find this file?" without loading the file. If nothing matches, it returns false.

Syntax

Call stream_resolve_include_path() with the values you need. Start with this line.

PHP
$path = stream_resolve_include_path("helpers.php");
CallWhat it does
stream_resolve_include_path("helpers.php")Returns the full path if helpers.php is found on the include_path.
stream_resolve_include_path("missing.php")Returns false when the file cannot be found.
basename(stream_resolve_include_path("x.php"))Keeps only the filename after a successful resolve.

Relative names are resolved against include_path entries. Absolute paths are checked as-is. Remember that include_path can contain several directories separated by PATH_SEPARATOR.

Library declarations
PHP
stream_resolve_include_path(string $filename): string|false

Parameters

ParameterDescription
filenameRequired. The file name to locate, usually a relative path.

Return Value

Return ValueDescription
stringThe resolved absolute path of the first match.
falseReturned when the file is not found on the include_path.

PHP Examples

Example 1 — Find a File on a Temporary Include Path

Create a temp file, put its directory on the include_path, then resolve the basename.

PHP
<?php
$dir = sys_get_temp_dir();
$file = "ctf_resolve_demo.php";
$path = $dir . DIRECTORY_SEPARATOR . $file;
file_put_contents($path, "<?php\n");

$old = get_include_path();
set_include_path($dir . PATH_SEPARATOR . $old);

$resolved = stream_resolve_include_path($file);
echo $resolved !== false ? "found" : "missing", PHP_EOL;
echo basename((string) $resolved), PHP_EOL;

set_include_path($old);
unlink($path);

How It Works

  1. A small PHP file is written into the system temp directory.
  2. set_include_path() puts that directory first on the include_path.
  3. stream_resolve_include_path() finds the file and returns its full path.
  4. We print found plus the basename so the demo stays offline-safe and path-stable.

Example 2 — Missing Files Return false

Ask for a name that does not exist and show the failure result.

PHP
<?php
$resolved = stream_resolve_include_path("no_such_ctf_file_123.php");
echo $resolved === false ? "false" : "unexpected", PHP_EOL;

How It Works

  1. The filename is deliberately unused.
  2. stream_resolve_include_path() searches the include_path.
  3. Nothing matches, so the return value is false.
  4. Compare with === false when you handle missing files.

Example 3 — Resolve Before Deciding to Include

Use the boolean outcome to print whether an include would succeed.

PHP
<?php
$dir = sys_get_temp_dir();
$file = "ctf_ready.php";
$path = $dir . DIRECTORY_SEPARATOR . $file;
file_put_contents($path, "<?php return 1;\n");

$old = get_include_path();
set_include_path($dir . PATH_SEPARATOR . $old);

if (stream_resolve_include_path($file) !== false) {
    echo "ready to include", PHP_EOL;
} else {
    echo "not found", PHP_EOL;
}

set_include_path($old);
unlink($path);

How It Works

  1. A temp file is placed on the include_path.
  2. stream_resolve_include_path() confirms PHP can see it.
  3. The script prints ready to include instead of loading the file.
  4. Cleanup restores include_path and deletes the temp file.

Frequently Asked Questions

It searches the include_path for a filename and returns the absolute path of the first match, or false if none is found.
No. It only resolves the path. Use include or require when you want to load the code.
A php.ini / runtime list of directories PHP searches for relative includes. Change it with set_include_path() or the include_path setting.
The directory may not be on the include_path, or you passed a different relative name. Check get_include_path() and the exact filename.
Yes. Absolute paths are checked directly. Relative names are searched through include_path entries.

Next: stream_select()

stream_select() waits until one or more streams are ready to read, write, or report an exc.

stream_select() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful