php的远程初步总结

Curl

PHP支持的由Daniel Stenberg创建的libcurl库允许你与各种的服务器使用各种类型的协议进行连接和通讯。libcurl目前支持http、https、ftp、gopher、telnet、dict、file和ldap协议。libcurl同时也支持HTTPS认证、HTTP POST、HTTP PUT、 FTP 上传(这个也能通过PHP的FTP扩展完成)、HTTP 基于表单的上传、代理、cookies和用户名+密码的认证。

有curl扩展支持,独立于其他的方法。

 

socket

扩展实现了一个低级别的接口,基于流行的BSD套接字Socket通信功能,作为一个套接字服务器以及客户端提供的可能性。

一个更通用的客户端套接字接口,看到stream_socket_client(),stream_socket_server(),fsockopen(),和pfsockopen()。

当使用这些功能,它是要记住,尽管他们中的很多人有相同的名称在他们的同行很重要,他们往往有不同的声明。请务必阅读说明,以避免混乱。

 

streams

作为一种概括文件,网络,数据压缩,和其他业务共享一组共同的功能和用途。在其最简单的定义,一个流是一个资源对象具有流化行为。那就是,它可以读取或写入一条直线,并可以fseek()到任意位置在流。

包装器附加代码告诉流如何处理特定的协议/编码。例如,在HTTP包装知道如何翻译一个URL到远程服务器上的文件的HTTP请求/ 1。有许多包装内置PHP在默认情况下(见支持的协议和包装),和额外的,定制的包装可以加在一个以stream_wrapper_register() PHP脚本,或直接从一个扩展使用API参考流的使用。因为任何品种的包装可以被添加到PHP,没有设置的限制,可以用它们来做什么。访问列表的当前注册的包装,使用stream_get_wrappers()。

一个参考方案/ /目标

■方案(字符串)可以用包装器的名称。例子包括:文件,HTTP,HTTPS,FTP,FTPS,compress.zlib,compress.bz2,和PHP。看到支持PHP内置协议列表包装和包装。如果没有指定函数的包装,则使用默认值(通常是文件:/ /)。

■目标取决于包装用。文件系统相关的数据流,这是一个典型的所需的文件的路径和文件名。网络相关的数据流,这是一个典型的主机名,往往一个路径附加。再次,看到支持描述内置流目标协议和包装。

------------------------------------以上三种为基本方式-------------------------------------------

file_get_contents

string file_get_contents ( string $filename [, bool $use_include_path [, resource $context [, int $offset [, int $maxlen ]]]] )

file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败,file_get_contents()将返回 FALSE

context

A valid context resource created with stream_context_create(). If you don't need to use a custom context, you can skip this parameter by NULL.

offset

The offset where the reading starts on the original stream.

Seeking (offset) is not supported with remote files. Attempting to seek on non-local files may work with small offsets, but this is unpredictable because it works on the buffered stream.

maxlen

Maximum length of data read. The default is to read until end of file is reached. Note that this parameter is applied to the stream processed by the filters.

从context,offset,maxlen参数可以看出这个函数的远程支持是streams扩展,context为流的上下文配置,maxlen将激活一个流的过滤器,详细信息在stream里说明。

fopen
resource fopen ( string $filename , string $mode [, bool $use_include_path [, resource $zcontext ]] )

所支持的协议列表见Supported Protocols and Wrappers。某些协议(也被称为 wrappers)支持 context 和/或 php.ini选项。参见相应的页面哪些选项可以被设定(例如 php.ini 中用于 http wrapper 的 user_agent 值)。

Note: 在 PHP 5.0.0 中增加了 对上下文(Context)的支持。 有关 上下文(Context) 的说明参见 Streams

 
对于fopen则直接返回的是一个流的资源对象,也是有streams扩展支持。
 
fsocketopen
resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )

Initiates a socket connection to the resource specified by hostname.

PHP supports targets in the Internet and Unix domains as described in 所支持的套接字传输器(Socket Transports)列表. A list of supported transports can also be retrieved using stream_get_transports().

The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking().

The function stream_socket_client() is similar but provides a richer set of options, including non-blocking connection and the ability to provide a stream context.

所支持的套接字传输器(Socket Transports)列表

Table of Contents

以下是 PHP 内置用于基于流的套接字函数例如 fsockopen()stream_socket_client()的各种 URL 风格的套接字传输器。这些传输器 不适用Sockets 扩展库

要得到自己的 PHP 版本中所安装的传输器列表,使用 stream_get_transports()

由此得知这些也是基于流的远程调用

附上stream的包装器

Table of Contents

 

posted on 2014-04-02 14:51  kudosharry  阅读(212)  评论(0编辑  收藏  举报

导航