downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | sites | links | conferences | my

search for in the

file://> <Context parameters
[edit] Last updated: Fri, 22 Jul 2011

view this page in

Supported Protocols and Wrappers

PHP comes with many built-in wrappers for various URL-style protocols for use with the filesystem functions such as fopen(), copy(), file_exists() and filesize(). In addition to these wrappers, it is possible to register custom wrappers using the stream_wrapper_register() function.

Note: The URL syntax used to describe a wrapper only supports the scheme://... syntax. The scheme:/ and scheme: syntaxes are not supported.

Table of Contents

file://> <Context parameters
[edit] Last updated: Fri, 22 Jul 2011
add a note add a note User Contributed Notes Supported Protocols and Wrappers
leonid at shagabutdinov dot com 23-Jul-2011 04:45
For https for windows enable this extension:

kwedeth at gmail dot com 25-May-2011 01:04
When daisy-chaining wrappers, I've found that the stream context only applies to the outside wrapper. For example, the following code will not work:


= array('http'=>array('header'=>"Accept-Encoding: gzip\r\n"));
$context = stream_context_create($options);

$html = file_get_contents('compress.zlib://', 0, $context);


The context in this case is useless for the compress.zlib:// wrapper but it does not get applied to http:// and the header will not be sent.
sebastian dot krebs at kingcrunch dot de 05-Feb-2011 12:49
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.
gjaman at gmail dot com 15-May-2008 09:15
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
jerry at gii dot co dot jp 17-Aug-2007 05:11
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.
sander at medicore dot nl 14-Jun-2007 11:25
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.
ben dot johansen at gmail dot com 25-Oct-2006 09:57

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

ben dot johansen at gmail dot com 29-Aug-2006 06:02
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
ben dot johansen at gmail dot com 29-Aug-2006 07:33
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
heitorsiller at uol dot com dot br 07-Jul-2006 02:55
For reading a XML stream, this will work just fine:

= file_get_contents('php://input');


Then you can parse the XML like this:


= xml_parser_create();

xml_parse_into_struct($xml, $arq, $vs);


$data = "";

$vs as $v){

$v['level'] == 3 && $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.
opedroso at NOSPAMswoptimizer dot com 12-Apr-2006 06:07
php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives.

Example use:

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

When reading a base64 encoded stream using php://input, be aware that you do not need to decode it, it will automatically be done for you.
nyvsld at gmail dot com 27-Nov-2005 06:28
php://stdin supports fseek() and fstat() function call,
while php://input doesn't.
drewish at katherinehouse dot com 25-Sep-2005 06:50
Be aware that contrary to the way this makes it sound, under Apache, php://output and php://stdout don't point to the same place.

= fopen('php://output', 'w');
$fs = fopen('php://stdout', 'w');

fputs($fo, "You can see this with the CLI and Apache.\n");
fputs($fs, "This only shows up on the CLI...\n");


Using the CLI you'll see:
  You can see this with the CLI and Apache.
  This only shows up on the CLI...

Using the Apache SAPI you'll see:
  You can see this with the CLI and Apache.
chris at free-source dot com 26-Apr-2005 07:52
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).
nargy at yahoo dot com 24-Sep-2004 10:16
When opening php://output in append mode you get an error, the way to do it:
fwrite($fp,"Hello, world !<BR>\n");
aidan at php dot net 27-May-2004 10:34
The contants:


Were introduced in PHP 4.3.0 and are synomous with the fopen('php://stdx') result resource.
lupti at yahoo dot com 29-Nov-2003 10:04
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.
sam at bigwig dot net 15-Aug-2003 03:02
[ 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.

show source | credits | sitemap | contact | advertising | mirror sites