套接字上下文選項
套接字上下文選項 — 套接字上下文選項列表
說明
套接字上下文選項可用於所有工作在套接字上的封裝協議,像
tcp
, http
和
ftp
。
更新日誌
版本 | 說明 |
---|---|
7.1.0 |
新增 tcp_nodelay 。
|
7.0.1 |
新增 ipv6_v6only 。
|
範例
示例 #1 基礎的 bindto
用法示例
<?php
// 使用 IP '192.168.0.100' 連線到網際網路
$opts = array(
'socket' => array(
'bindto' => '192.168.0.100:0',
),
);
// 使用 IP '192.168.0.100' 和埠 '7000' 連線到網際網路
$opts = array(
'socket' => array(
'bindto' => '192.168.0.100:7000',
),
);
// 使用 IPv6 地址 '2001:db8::1' 和埠 '7000' 連線到網際網路
$opts = array(
'socket' => array(
'bindto' => '[2001:db8::1]:7000',
),
);
// 使用埠 '7000' 連線到網際網路
$opts = array(
'socket' => array(
'bindto' => '0:7000',
),
);
// 建立上下文...
$context = stream_context_create($opts);
// ...並使用它來讀取數據
echo file_get_contents('http://www.example.com', false, $context);
?>