![](/img/trans.png)
[英]php - notification in stream_context_set_params() not called
[英]stream_context_set_params vs. stream_context_set_option
文檔說的是什么
從閱讀php.net,我覺得stream_context_set_params幾乎和stream_context_set_option一樣。 即。
http://www.php.net/manual/en/function.stream-context-set-params.php
bool stream_context_set_params ( resource $stream_or_context , array $params )
http://www.php.net/manual/en/function.stream-context-set-option.php
bool stream_context_set_option ( resource $stream_or_context , array $options )
stream_context_set_option
支持stream_context_set_params
沒有的其他參數,否則看起來他們正在做同樣的事情。 至少在理論上。
我的測試顯示了什么
我自己的測試建議不然,實際上讓我想知道stream_context_set_params
實際上做了什么(如果有的話)。
使用stream_context_set_params
...
<?php
$ctx = stream_context_create();
stream_context_set_params($ctx, array('zz' => array('zz' => 'zz')));
print_r(stream_context_get_options($ctx));
這打印出以下內容(令我驚訝的是):
Array
(
)
使用stream_context_set_option
...
<?php
$ctx = stream_context_create();
stream_context_set_option($ctx, array('zz' => array('zz' => 'zz')));
print_r(stream_context_get_options($ctx));
這打印出以下內容(正如我所料):
Array
(
[zz] => Array
(
[zz] => zz
)
)
所以我真的不知道。 有任何想法嗎?
bool stream_context_set_params ( resource $stream_or_context , array $params )
在這個時候它只是采用'notification'參數密鑰,並由stream_notification_callback
。
您可以在此處查看支持的上下文參數列表: http : //php.net/manual/en/context.params.php
<?php $opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
),
);
$context = stream_context_create($opts);
stream_context_set_params($context
, ['notification' => 'your_call_back_notification']
);
var_dump(stream_context_get_params($context));
輸出:
Array(
[notification] => your_call_back_notification
[options] => Array
(
[http] => Array
(
[method] => GET
[header] => Accept-language: en
Cookie: foo=bar
)
)
)
通知回調可能有警告錯誤,它必須是有效的可調用。 請訪問http://php.net/manual/en/function.stream-notification-callback.php了解更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.