Current Location: Home> Function Categories> socket_clear_error

socket_clear_error

Clear an error on the socket or the previous error code
Name:socket_clear_error
Category:Sockets
Programming Language:php
One-line Description:Clear the last socket error or the last socket operation error

Function name: socket_clear_error()

Applicable version: PHP 4, PHP 5, PHP 7

Function description: socket_clear_error() function is used to clear the last socket error or the most recent socket operation error.

Syntax: bool socket_clear_error ( resource $socket )

parameter:

  • $socket: represents a valid socket resource, returned through socket_create() or socket_accept() functions.

Return value: Return true if successful, return false if failed.

Example:

 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { echo "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n"; } // 进行一些socket操作,可能会产生错误if (socket_clear_error($socket)) { echo "最近一次的socket 错误已被清除。\n"; } else { echo "清除socket 错误失败。\n"; }

Notes:

  • The socket_clear_error() function can only clear the last socket error or the last socket operation error. If you want to clear other errors, you need to execute the corresponding socket function to trigger the error.
  • The socket_clear_error() function returns true after clearing the error, but does not guarantee that the socket operation will be successful.