PHP stream_get_wrappers() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Stream

Definition

In PHP, stream_get_wrappers() returns the names of the stream wrappers available right now, such as file, http, php, and data.

Wrappers let fopen() and related functions understand URL-style paths. Built-in wrappers ship with PHP; custom ones appear after stream_wrapper_register() (or its alias stream_register_wrapper()).

Syntax

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

PHP
$wrappers = stream_get_wrappers();
CallWhat it does
stream_get_wrappers()Returns an array of wrapper name strings.
in_array("php", stream_get_wrappers())Checks whether the php:// wrapper is available.
in_array("file", stream_get_wrappers())Checks whether the file:// wrapper is available.

Wrapper names are short labels like "http" or "php", not full URLs. To open a stream you still write php://memory or https://example.com.

Library declarations
PHP
stream_get_wrappers(): array

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
arrayIndexed array of registered wrapper names.

PHP Examples

Example 1 — Check Built-in Wrappers

Verify that file, php, and data wrappers are present.

PHP
<?php
$wrappers = stream_get_wrappers();
foreach (["file", "php", "data"] as $name) {
    echo $name, ": ", in_array($name, $wrappers, true) ? "yes" : "no", PHP_EOL;
}

How It Works

  1. stream_get_wrappers() loads the current wrapper list.
  2. We test three wrappers that almost every PHP build includes.
  3. in_array() prints yes when each name is found.
  4. These wrappers power ordinary files, php:// streams, and data:// URIs.

Example 2 — Open php:// After Confirming the Wrapper

Only open a memory stream when the php wrapper is registered.

PHP
<?php
if (!in_array("php", stream_get_wrappers(), true)) {
    echo "php wrapper missing", PHP_EOL;
    return;
}

$fp = fopen("php://memory", "r+");
fwrite($fp, "ok");
rewind($fp);
echo stream_get_contents($fp), PHP_EOL;
fclose($fp);

How It Works

  1. The script checks for the php wrapper first.
  2. fopen("php://memory") opens an in-memory stream.
  3. A short string is written and read back.
  4. The printed result is ok.

Example 3 — Count Wrappers Without Dumping Them

Report whether the list is non-empty using a stable yes/no message.

PHP
<?php
$n = count(stream_get_wrappers());
echo "wrappers registered: ", $n > 0 ? "yes" : "no", PHP_EOL;
echo "at least 3: ", $n >= 3 ? "yes" : "no", PHP_EOL;

How It Works

  1. count() measures the wrapper list.
  2. Printing the raw total can differ between PHP builds.
  3. Comparing against 0 and 3 keeps the tutorial output fixed.
  4. Both answers are yes on a normal install.

Frequently Asked Questions

It returns an array of stream wrapper names currently registered, including built-ins like file and php.
A wrapper teaches PHP how to open a class of URLs. For example, the php wrapper handles php://memory and php://temp.
Create a stream wrapper class and register it with stream_wrapper_register() or the alias stream_register_wrapper().
Often yes, but allow_url_fopen and build options matter. Check the list, then also check your php.ini settings.
Wrappers are for fopen-style URLs. Transports are for socket addresses like tcp://host:port.

Next: stream_is_local()

stream_is_local() reports whether a stream (or a stream URL string) refers to a local reso.

stream_is_local() 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