©
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
(PHP 4 >= 4.2.0, PHP 5)
socket_clear_error — 清除套接字或者最后的错误代码上的错误
$socket
] )这个函数清除给定的套接字上的错误代码或是最后一个全局的套接字如果套接字没有指定的话
这个函数允许明确的重置错误代码值 不论是一个套接字或者最后全局错误代码的扩展, 这对在检测应用的一部分是否有错误发生是十分有用的
socket
用 socket_create() 创建的有效的套接字资源。
没有返回值。
[#1] raphael at engenhosweb dot com dot br [2011-07-27 14:45:40]
You can do this too, with anonymous function:
<?php
$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or function() {
$errstr = socket_strerror(socket_last_error());
echo ("Failed to create socket: " . $errstr);
socket_clear_error();
};
?>
[#2] ludvig dot ericson at gmail dot com [2006-05-23 16:08:13]
If you want to clear your error in a small amount of code, do a similar hack as to what most people do in SQL query checking,
<?php
$result = mysql_query($sql) or die();
?>
It could look like this:
<?php
if (!($socket = socket_create()) {
echo ("Failed to create socket: " . socket_strerror(socket_last_error()) and socket_clear_error());
}
?>
As you can see, I use "and" here instead of "or" since the first part will always return true, thus if you use or PHP's lazy boolean checking will not execute the last part, which it will with an and if the first part is true.