socket_clear_error

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

socket_clear_error清除套接字或者最后的错误代码上的错误

说明

socket_clear_error ( resource $socket = ? ) : void

这个函数清除给定的套接字上的错误代码或是最后一个全局的套接字如果套接字没有指定的话

这个函数允许明确的重置错误代码值 不论是一个套接字或者最后全局错误代码的扩展, 这对在检测应用的一部分是否有错误发生是十分有用的

参数

socket

socket_create()创建的有效的套接字资源。

返回值

没有返回值。

参见

User Contributed Notes

raphael at engenhosweb dot com dot br 27-Jul-2011 02:45
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();
        };
?>
ludvig dot ericson at gmail dot com 23-May-2006 04:08
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(/* Whatever code */);
?>

It could look like this:
<?php
if (!($socket = socket_create(/* Whatever code */)) {
    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.