List of Supported Protocols/Wrappers


The following is a list of the various URL style protocols that PHP has built-in for use with the filesystem functions such as fopen() and copy(). In addition to these wrappers, as of PHP 4.3.0, you can write your own wrappers using PHP script and stream_wrapper_register().


All versions of PHP. Explicitly using file:// since PHP 5.0.0.

  • /path/to/file.ext
  • relative/path/to/file.ext
  • fileInCwd.ext
  • C:/path/to/winfile.ext
  • C:\path\to\winfile.ext
  • \\smbserver\share\path\to\winfile.ext
  • file:///path/to/file.ext

Filesystem is the default wrapper used with PHP and represents the local filesystem. When a relative path is specified (a path which does not begin with /, \, \\, or a Windows drive letter) the path provided will be applied against the current working directory. In many cases this is the directory in which the script resides unless it has been changed. Using the CLI sapi, this defaults to the directory from which the script was called.

With some functions, such as fopen() and file_get_contents(), include_path may be optionally searched for relative paths as well.

Wrapper Summary
Attribute Supported
Restricted by allow_url_fopen No
Allows Reading Yes
Allows Writing Yes
Allows Appending Yes
Allows Simultaneous Reading and Writing Yes
Supports stat() Yes
Supports unlink() Yes
Supports rename() Yes
Supports mkdir() Yes
Supports rmdir() Yes


[ Editor's Note: There is a way to know.  All response headers (from both the final responding server and intermediate redirecters) can be found in $http_response_header or stream_get_meta_data() as described above. ]

If you open an HTTP url and the server issues a Location style redirect, the redirected contents will be read but you can't find out that this has happened.

So if you then parse the returned html and try and rationalise relative URLs you could get it wrong.
2003-08-15 11:02:24
I find using file_get_contents with php://input is very handy and efficient. Here is the code:

$request = "";
$request = file_get_contents("php://input");

I don't need to declare the URL filr string as "r". It automatically handles open the file with read.

I can then use this $request string to your XMLparser as data.
2003-11-29 04:04:02
The contants:


Were introduced in PHP 4.3.0 and are synomous with the fopen('php://stdx') result resource.
2004-05-27 06:34:21
When opening php://output in append mode you get an error, the way to do it:
fwrite($fp,"Hello, world !<BR>\n");
2004-09-24 06:16:07
If you're looking for a unix based smb wrapper there isn't one built in,  but I've had luck with (tarball link at the end).
2005-04-26 15:52:45
php://stdin supports fseek() and fstat() function call, 
while php://input doesn't.
2005-11-27 12:28:15
For reading a XML stream, this will work just fine:



Then you can parse the XML like this:





$data "";

$vs as $v){

$v['level'] == && $v['type'] == 'complete')
$data .= "\n".$v['tag']." -> ".$v['value'];



PS.: This is particularly useful for receiving mobile originated (MO) SMS messages from cellular phone companies.
2006-07-07 10:55:04
In trying to do AJAX with PHP and Javascript, I came upon an issue where the POST argument from the following javascript could not be read in via PHP 5 using the $_REQUEST or $_POST. I finally figured out how to read in the raw data using the php://input directive.
Javascript code:
      //create request instance     
      xhttp = new XMLHttpRequest();
      // set the event handler
      xhttp.onreadystatechange = serviceReturn;
      // prep the call, http method=POST, true=asynchronous call
      var Args = 'number='+NbrValue;"POST", "http://<?php echo $_SERVER['SERVER_NAME'?>/webservices/ws_service.php", true);
      // send the call with args

PHP Code:
    //read the raw data in
    $roughHTTPPOST = file_get_contents("php://input"); 
    //parse it into vars
2006-08-29 03:33:17
Example of how to use the php://input to get raw post data

//read the raw data in
$roughHTTPPOST = file_get_contents("php://input"); 
//parse it into vars

if you do readfile("php://input") you will get the length of the post data
2006-08-29 14:02:31

I found that if I added this line to the AJAX call, the values would show up in the $_POST

2006-10-25 17:57:21
to create a raw tcp listener system i use the following:

xinetd daemon with config like:
service test
        disable      = no
        type         = UNLISTED
        socket_type  = stream
        protocol     = tcp
        bind         =
        port         = 12345
        wait         = no
        user         = apache
        group        = apache
        instances    = 10
        server       = /usr/local/bin/php
        server_args  = -n [your php file here]
        only_from    = #gotta love the security#
        log_type     = FILE /var/log/phperrors.log
        log_on_success += DURATION

now use fgets(STDIN) to read the input. Creates connections pretty quick, works like a charm.Writing can be done using the STDOUT, or just echo. Be aware that you're completely bypassing the webserver and thus certain variables will not be available.
2007-06-14 07:25:26
Not only are STDIN, STDOUT, and STDERR only allowed for CLI programs, but they are not allowed for programs that are read from STDIN. That can confuse you if you try to type in a simple test program.
2007-08-17 13:11:43
You can decompress (gzip) a input stream by combining wrappers:

eg:  $x = file_get_contents("compress.zlib://php://input"); 

I used this method to decompress a gzip stream that was pushed to my webserver
2008-05-15 17:15:11
The stream php://temp/maxmemory:$limit stores the data in memory unless the limit is reached. Then it will write the whole content the a temporary file and frees the memory. I didnt found a way to get at least some of the data back to memory.
2011-02-04 18:49:01
For https for windows enable this extension:

2011-07-23 00:45:18
For php://filter the /resource=foo part must come last. And foo needs no escaping at all.
php://filter/resource=foo/read=somefilter would try to open a file 'foo/read=somefilter' while php://filter/read=somefilter/resource=foo will open file 'foo' with the somefilter filter applied.
2012-05-04 10:00:07
Be aware of code injection, folks - like anything else you take from the user, SANITISE IT FIRST.  This cannot be stressed enough - if I had a dollar for each time I saw code where form input was taken and directly used (by myself as well, I've been stupid too) I'd probably own PHP.  While using data from a form in a URL wrapper is asking for trouble, you can greatly minimise the trouble by making sure your inputs are sane and not likely to provide an opening for the LulzSec of the world to cause havoc.
2012-06-05 04:46:18
Here is a snippet to read compressed raw post data without enabling global variables.

I needed it to read xml posted data submitted by ocs agent. The data was sent as Content-Type: application/x-compressed (zlib compressed data).

It seems related to an old bug which still seems broken :

The important part is the default window set to 15 instead of -15.

Code snippet
$fh fopen('php://input''rb');
stream_filter_append($fh'zlib.inflate'STREAM_FILTER_READ, array('window'=>15));
feof($fh)) {
$data .= fread($fh8192);
2012-08-06 17:00:52
You can use "php://input" to accept and parse "PUT", "DELETE", etc. requests.

// Example to parse "PUT" requests 
parse_str(file_get_contents('php://input'), $_PUT);

// The result

(very useful for Restful API)
2013-03-05 14:06:02
If my understanding of the implementing code is correct, every time you open a php://memory stream, you get new storage allocated. That is to say, php://memory isn't a shared bank of memory.
2013-04-23 19:42:46
In PHP 5.4+ you can read multipart data via php://input if you set enable_post_data_reading to Off. 

Of course if you set it to off, the $_POST and $_FILES superglobals won't be populated at all. It's entirely up to you to parse the data now.
2013-05-02 00:17:58
The use of php://temp/maxmemory as a stream counts towards the memory usage of the script; you are not specifying a new memory pool by using this type of stream.
As noted in the documentation however, this stream type will start to write to a file after the specified maxmemory limit is exceeded. This file buffer is NOT observed by the memory limit.
This is handy if you want your script to have a reasonably small memory limit (eg 32MB) but but still be able to handle a huge amount of data in a stream (eg 256MB)

The only works if you use stream functions like fputs(); if you use $buffer .= 'string'; or $buffer = $buffer . 'string'; you're calling your stream data back into PHP and this will hit the limiter.

As a practical example:

// 0.5MB memory limit
// 2MB stream limit
$buffer fopen('php://temp/maxmemory:1048576''r+');
$x 0;
// Attempt to write 1MB to the stream
while ($x 1*1024*1024) {
"This will never be displayed";

However, change fopen to use php://temp/maxmemory:1 (one byte, rather than one megabyte) and it will begin writing to the unlimited file stream immediately, avoiding memory limit errors.
2013-06-03 07:46:24
A useful way to handle large file uploads is to do something like:


as this avoids using lots of memory just to buffer the file content.

The correct mime type for this should be "application/octet-stream" however if you set this or any other recognised mime type other than "multipart/form-data" on your POST then $HTTP_RAW_POST_DATA is populated and the memory is consumed anyway. 

Setting the mime type to "multipart/form-data" raises “PHP Warning:  Missing boundary in multipart/form-data POST data in Unknown on line 0” however it seems to work without a problem.
2014-02-13 21:14:01
While writing to error stream, error_log() function comes as a shorthand to writing to php://stderr . This function also allows writing to web server log when running through a web server such as apache.
2014-09-09 01:35:08
Each stream pointer to php://memory and php://temp has its own memory allocation, so you can open many stream pointers to store your separated values.

$fp2 fopen("php://temp""r+");



feof($fp)) {

feof($fp2)) {

Closing their stream handles will also free the allocated memory.

php://memory stream type is MEMORY, while php://temp stream type is STDIO FILE*.
2014-11-18 13:05:33
//enable $HTTP_RAW_POST_DATA when necessary
$HTTP_RAW_POST_DATA file_get_contents('php://input');
2015-11-05 20:45:38
Note that STDIN and similar are defined only in CLI
2016-01-28 22:58:02
If you want to filter incoming data through php://input use this:


I couldn't find any documentation to explain how to do this. All the examples I came across suggested that a full and actual URL had to be used (which didn't work for me).

This seems to work though.
2017-08-13 15:37:01
Even though their names will be the same, you can have more than one //memory or //temp stream open concurrently; each time you fopen() such a stream, a NEW stream will be opened independently of the others.

This is hinted at by the fact you don't add any unique identifier to the path when creating such streams, but isn't said explicitly.


fopen('php://memory''r+'); // $hello, $php, $world are all different streams.
$php  fopen('php://memory''r+');
$world fopen('php://memory''r+'); // They're not the same stream opened three times.

fputs($hello"Hello ");
fputs($php"PHP ");

'['stream_get_contents($hello), ']['stream_get_contents($php), ']['stream_get_contents($world), ']';
// If they were the same stream the output would be "[World!][World!][World!]".
2018-01-11 01:56:06
Be forewarned:

the file:// protocol used in file_get_contents is used as the default for "any unrecognized protocol." Thus:


will deliver the same as 

2018-03-29 09:02:21

    Поддержать сайт на родительском проекте КГБ