![](/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.