<?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’,
),
);
// ポート番号 ‘7000’ でインターネットに接続する
$opts = array(
‘socket’ => array(
‘bindto’ => ‘0:7000’,
),
);
// コンテキストを作成し…
$context = stream_context_create($opts);
// …そしてデータを取得するためにそれを使用する
echo file_get_contents(‘http://www.example.com’, false, $context);
?>
複数のインターフェース(NIC)があるサーバ等のマシンから外にリクエストを送る際、利用する経路を指定する方法。
1年前 | 固定リンク | 2011年 4月 19日 | 
