php 警告重定向
我使用 snmp2_real_walk
函数。
$tmp = snmp2_real_walk($ip, '***'.$vlan, $title, 100000,10);
当 oid 正确且设备正常工作时,我会得到所需的输出。但我想处理警告:无效的对象标识符...
或No response from 192.168.19.249...
或其他。我的问题是:如何将这些警告重定向到我的变量中?
或者是否有其他功能可以显示这些警告?
谢谢!
I use snmp2_real_walk
function.
$tmp = snmp2_real_walk($ip, '***'.$vlan, $title, 100000,10);
When oid is correct and the device is working i get the desired output. But i want to handle warnings: Invalid object identifier...
or No response from 192.168.19.249...
or whatever. My problem is: how can i either redirect those warnings into my variable?
or is there some another function which shows these warnings?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以查看 set_error_handler 来为此特定情况设置您自己的错误处理程序,然后恢复错误处理程序进行函数调用后。
You could also have a look at set_error_handler to set your own error handler for this specific case, and then restore the error handler after making the function call.
使用
error_get_last()
是解决方案:)using
error_get_last()
was the solution :)看一下 PHP 的 set_error_handler 函数。 snmp2_real_walk 在遇到错误时生成 E_WARNING 消息,set_error_handler 将允许您捕获这些消息并记录它们等。
Take a look at PHP's set_error_handler function. snmp2_real_walk generates E_WARNING messages when it encounters an error, set_error_handler will allow you to capture these and log them etc.
您想要使用 try-catch 块来捕获异常,这是根据您的函数调整的 PHP 文档中的示例:
PHP 手册页:
http://php.net/manual/en/language.exceptions.php
You want to use a try-catch block to catch your exception here's an example from PHP's documentation adjusted to your function:
The PHP Manual Page:
http://php.net/manual/en/language.exceptions.php