Home > Article > PHP Framework > swoole method to get message sending failure error
Send data to the client, function prototype:
bool Server->send(mixed $fd, string $data, int $serverSocket = -1);
The sending process is asynchronous, the bottom layer will automatically listen and write, and gradually send the data to the client
Parameters
$fd, the client’s file descriptor
$data, the data sent, the TCP protocol must not exceed 2M, buffer_output_size can be modified to change the maximum packet length allowed to be sent
$serverSocket, this parameter is required when sending data to the Unix Socket DGRAM peer. The TCP client does not need to fill in
Return value
If the sending is successful, true will be returned
Failure to send will return false. Call the $server->getLastError() method to get the failure error code
Server->getLastError
Get the latest Error code for an operation error. Business code can execute different logic based on error code types.
function Server->getLastError()
Returns an integer numeric error code
Send failure error
1001 The connection has been closed by the server, this error occurs Generally, $serv->close() has been executed in the code to close a certain connection, but $serv->send() is still called to send data to this connection.
1002 The connection has been closed by the client. The Socket has been closed and data cannot be sent to the peer
1003 Close is being executed, $serv->send() must not be used in the onClose callback function
1004 The connection has been closed
1005 The connection does not exist, and the incoming $fd may be wrong.
1007 Timeout data is received. After TCP closes the connection, some data may remain in the pipe buffer, and this part of the data will be Discard
1008 The send buffer is full and the send operation cannot be performed. This error indicates that the peer of this connection cannot receive data in time, causing the send buffer to be full
1202 The data sent exceeds server->buffer_output_size setting
Recommended learning: swoole video tutorial
The above is the detailed content of swoole method to get message sending failure error. For more information, please follow other related articles on the PHP Chinese website!