PHP 套接字上下文选项
简介
可以通过 stream_context_create() 和 stream_context_set_option() 函数配置的各种上下文选项和参数自定义对文件系统和其他各种流包装器的访问。
以下列表演示了所有可用于通过套接字(如 tcp、http 和 ftp 等)工作的包装器的各种 套接字上下文选项。
| bindto | 指定用于访问网络的 IP 地址(IPv4 或 IPv6)和/或端口号。(ip:port for IPv4 [ip]:port for IPv6)。 |
| backlog | 限制套接字监听队列中的未完成连接的数量。 |
| ipv6_v6only | 覆盖映射 IPv4 到 IPv6 的操作系统默认设置。 |
| so_reuseport | 允许对同一 ip:port 对进行多个绑定。 |
| so_broadcast | 启用向/从广播地址发送和接收数据。 |
| tcp_nodelay | 如果为 TRUE,则适当地设置 SOL_TCP,NO_DELAY=1,禁用 TCP Nagle 算法。 |
示例
<?php
// connect to the internet using the '192.168.0.100' IP
$opts = array(
'socket' => array(
'bindto' => '192.168.0.100:0',
),
);
// ...and use it to fetch the data
echo file_get_contents('http://www.example.com', false, $context);
?>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP