套接字上下文選項 — 套接字上下文選項列表
套接字上下文選項可用于所有工作在套接字上的封裝協(xié)議,像
tcp, http 和
ftp。
| 版本 | 說明 |
|---|---|
| 7.1.0 |
添加 tcp_nodelay。
|
| 7.0.1 |
添加 ipv6_v6only。
|
示例 #1 基礎的 bindto 用法示例
<?php
// 使用 IP '192.168.0.100' 連接到互聯(lián)網
$opts = array(
'socket' => array(
'bindto' => '192.168.0.100:0',
),
);
// 使用 IP '192.168.0.100' 和端口 '7000' 連接到互聯(lián)網
$opts = array(
'socket' => array(
'bindto' => '192.168.0.100:7000',
),
);
// 使用 IPv6 地址 '2001:db8::1' 和端口 '7000' 連接到互聯(lián)網
$opts = array(
'socket' => array(
'bindto' => '[2001:db8::1]:7000',
),
);
// 使用端口 '7000' 連接到互聯(lián)網
$opts = array(
'socket' => array(
'bindto' => '0:7000',
),
);
// 創(chuàng)建上下文...
$context = stream_context_create($opts);
// ...并使用它來讀取數(shù)據
echo file_get_contents('http://www.example.com', false, $context);
?>