Поддерживаемые протоколы и обработчики (wrappers)

PHP поставляется с множеством встроенных обработчиков для различных URL-протоколов для использования с функциями файловой системы, таких как fopen(), copy(), file_exists() и filesize(). В дополнение к этим обработчикам, можно регистрировать собственные обработчики, используя функцию stream_wrapper_register().

Замечание: URL синтаксис, используемый для описания обработчика, может быть только вида scheme://.... Варианты синтаксиса scheme:/ и scheme: не поддерживаются.

Содержание

  • file:// — Доступ к локальной файловой системе
  • http:// — Доступ к URL-адресам по протоколу HTTP(s)
  • ftp:// — Доступ к URL-адресам по протоколу FTP(s)
  • php:// — Доступ к различным потокам ввода-вывода
  • zlib:// — Сжатые потоки
  • data:// — Схема Data (RFC 2397)
  • glob:// — Нахождение путей, соответствующих шаблону
  • phar:// — PHP архив
  • ssh2:// — Secure Shell 2
  • rar:// — RAR
  • ogg:// — Аудио потоки
  • expect:// — Потоки для взаимодействия с процессами

Коментарии

[ 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
http://php5.kiev.ua/manual/ru/wrappers.html
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
http://php5.kiev.ua/manual/ru/wrappers.html
The contants:

* STDIN
* STDOUT
* STDERR

Were introduced in PHP 4.3.0 and are synomous with the fopen('php://stdx') result resource.
2004-05-27 06:34:21
http://php5.kiev.ua/manual/ru/wrappers.html
When opening php://output in append mode you get an error, the way to do it:
$fp=fopen("php://output","w");
fwrite($fp,"Hello, world !<BR>\n");
fclose($fp);
2004-09-24 06:16:07
http://php5.kiev.ua/manual/ru/wrappers.html
If you're looking for a unix based smb wrapper there isn't one built in,  but I've had luck with http://www.zevils.com/cgi-bin/viewcvs.cgi/libsmbclient-php/ (tarball link at the end).
2005-04-26 15:52:45
http://php5.kiev.ua/manual/ru/wrappers.html
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.

<?php
$fo 
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");

fclose($fo);
fclose($fs);
?>

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.
2005-09-25 02:50:08
http://php5.kiev.ua/manual/ru/wrappers.html
php://stdin supports fseek() and fstat() function call, 
while php://input doesn't.
2005-11-27 12:28:15
http://php5.kiev.ua/manual/ru/wrappers.html
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.
2006-04-12 14:07:51
http://php5.kiev.ua/manual/ru/wrappers.html
For reading a XML stream, this will work just fine:
<?php

$arq 
file_get_contents('php://input');

?>

Then you can parse the XML like this:

<?php

$xml 
xml_parser_create();

xml_parse_into_struct($xml$arq$vs);

xml_parser_free($xml);

$data "";

foreach(
$vs as $v){

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

echo 
$data;

?>

PS.: This is particularly useful for receiving mobile originated (MO) SMS messages from cellular phone companies.
2006-07-07 10:55:04
http://php5.kiev.ua/manual/ru/wrappers.html
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;
      xhttp.open("POST", "http://<?php echo $_SERVER['SERVER_NAME'?>/webservices/ws_service.php", true);
      // send the call with args
      xhttp.send(Args);

PHP Code:
    //read the raw data in
    $roughHTTPPOST = file_get_contents("php://input"); 
    //parse it into vars
    parse_str($roughHTTPPOST);
2006-08-29 03:33:17
http://php5.kiev.ua/manual/ru/wrappers.html
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
parse_str($roughHTTPPOST);

if you do readfile("php://input") you will get the length of the post data
2006-08-29 14:02:31
http://php5.kiev.ua/manual/ru/wrappers.html
followup:

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

xhttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
2006-10-25 17:57:21
http://php5.kiev.ua/manual/ru/wrappers.html
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         = 127.0.0.1
        port         = 12345
        wait         = no
        user         = apache
        group        = apache
        instances    = 10
        server       = /usr/local/bin/php
        server_args  = -n [your php file here]
        only_from    = 127.0.0.1 #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
http://php5.kiev.ua/manual/ru/wrappers.html
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
http://php5.kiev.ua/manual/ru/wrappers.html
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
http://php5.kiev.ua/manual/ru/wrappers.html
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
http://php5.kiev.ua/manual/ru/wrappers.html
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:

<?php

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

$html file_get_contents('compress.zlib://http://example.com/resource.gz'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.
2011-05-24 21:04:04
http://php5.kiev.ua/manual/ru/wrappers.html
For https for windows enable this extension:

extension=php_openssl.dll
2011-07-23 00:45:18
http://php5.kiev.ua/manual/ru/wrappers.html
/**********************************/
Example JSON Request:
{
    "username" : "rakeshnsony",
    "password" : "abcdefg"
}
/**********************************/
<?php

//To access json format data
$requestBody file_get_contents('php://input');
$requestBody json_decode($requestBody);

echo 
"username is: ".$requestBody->username;

echo 
"<br /><br />";

echo 
"password is: ".$requestBody->password;
//
2012-03-19 12:18:43
http://php5.kiev.ua/manual/ru/wrappers.html
Автор:
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
http://php5.kiev.ua/manual/ru/wrappers.html
Автор:
Dangerous stuff. Had php injection attacks like:

?-dallow_url_include%253don+-dauto_prepend_file%253dphp://input

due to this
2012-05-19 01:12:18
http://php5.kiev.ua/manual/ru/wrappers.html

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