📜  PHP中的协议和包装器

📅  最后修改于: 2022-05-13 01:56:32.954000             🧑  作者: Mango

PHP中的协议和包装器

PHP中有各种不同类型的 URL 样式协议的内置包装器。这些包装器用于许多其他文件系统功能。在PHP中也允许注册自定义包装器。可以通过 stream_wrapper_register()函数来完成。

在PHP中,支持的 URL 语法是 scheme://

PHP中不支持的 URL 语法有:

  • 方案:/
  • 方案:

PHP中有 12 个包装器。

WrapperWorkDescription
file://Local file system is accessed through itThis default wrapper in PHP is representing local file system. 
http://HTTP(s) URLs is accessed through itThe mentioned relative path is applied against present working directory.
ftp://FTP(s) URLs is accessed through itNew files are created and earlier ones are accessed through FTP. If passive mode FTP is not supported by the server then there is a fail in connection.
php://Multiple type of I/O streams is accessed through itI/O error file descriptors, streams, inmemory can be read and written through other I/O streams. 
zlib://Streams are compressedWorks in a similar manner as gzopen(), except the fact that other file system functions can be used with it.
data://Data (RFC 2397)Reading contents or media type which can be later printed.
glob:// Finding pathnames such that it matches the patternThe most common use includes searching over the directory and printing a file’s name and size.
phar:// Archive in PHPRead and write can be performed individually as well as simultaneously but cannot be appended.
ssh2://Shell 2 is securedThis wrapper is not available by default in PHP, for accessing it  SSH2 extension needs to be downloaded.
rar://RARThe URL path(encoded) is taken to RAR archive where RAR can be relative or absolute. Other optional things that are stored in archive are – asterik(*), number sign(#) and entry name. Both directories and files are accessible through it.
ogg://Audio stream The ogg:// wrapper opens the file that are compressed audio that have been encoded through OGG/Vorbis codec. Even if the files are appended they are  compressed audio. This wrapper is not available by default in PHP, for accessing it  OGG/Vorbis  extension needs to be downloaded.
expect://Interaction streams are processed This wrapper makes stderr, process’es stdio and stdout accessible. This wrapper is not available by default in PHP, for accessing it Expect  extension needs to be downloaded.