stream_notification_callback似乎不起作用

时间:2013-04-01 18:56:59

标签: php stream

http://www.php.net/manual/en/function.stream-notification-callback.php

因为我不希望以下内容产生错误:

<?php
stream_context_create(array('notification' => 'callback'));

......但确实如此:

Warning: stream_context_create(): options should have the form ["wrappername"]["optionname"] = $value in /path/to/file.php on line 2

这也会产生错误:

<?php
$ctx = stream_context_create();
stream_context_set_option($ctx, array('notification' => 'callback'));

具有讽刺意味的是,stream_notification_callback示例中的代码不会产生错误。但是因为它使用的是stream_context_set_params而不是stream_context_set_option我不相信它实际上在做任何事情lol:

stream_context_set_params vs. stream_context_set_option

1 个答案:

答案 0 :(得分:0)

该函数等待数组内的数组,因此必须将代码更改为:

stream_context_create(array('wrapper' => array ('notification' => 'callback')));