The right way for forcing IPv6 is 'bindto' => '[::]:0'ソケットコンテキストオプション — ソケットコンテキストオプション一覧
   ここでは、ソケット越しに動作するラッパー
   すなわち 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);
?>You can set "bindto" to "0:0" to force use IPv4 instead of IPv6. And probably "[0]:0" to force use IPv6, thou this I couldn't test.