stream_context_set_options

指定されたコンテキストのオプションを設定する

説明

bool stream_context_set_options(resource $context, array $options)

指定されたコンテキストのオプションを設定します。

パラメータ

context

オプションを適用するストリーム、またはコンテキストリソース。

options

context に設定するオプション。

注意:

options は、 $array['wrapper']['option'] = $value のフォーマットからなる連想配列でなければいけません。

ストリームオプションの一覧は コンテキストオプションとパラメータ を参照ください。

戻り値

成功した場合に true を、失敗した場合に false を返します。

例1 stream_context_set_options の例

<?php

$context 
stream_context_create();

$options = [
    
'http' => [
        
'protocol_version' => 1.1,
        
'user_agent' => 'PHPT Agent',
    ],
];

stream_context_set_options($context$options);
var_dump(stream_context_get_options($context));
?>

上の例の出力は以下となります。

array(1) {
  ["http"]=>
  array(2) {
    ["protocol_version"]=>
    float(1.1)
    ["user_agent"]=>
    string(10) "PHPT Agent"
  }
}

参考

  • stream_context_set_option