php socket_write 返回值,socket_write()

socket_write()

(PHP 4 >= 4.1.0, PHP 5, PHP 7)

Write to a socket

说明socket_write(resource$socket,string$buffer[,int$length= 0]):int

The function socket_write() writes to the$socketfrom the given$buffer.

参数$socket$bufferThe buffer to be written.$lengthThe optional parameter$lengthcan specify an alternate length of bytes written to the socket. If this length is greater than the buffer length, it is silently truncated to the length of the buffer.

返回值

Returns the number of bytes successfully written to the socket 或者在失败时返回FALSE. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.Note:

It is perfectly valid for socket_write() to return zero which means no bytes have been written. Be sure to use the===operator to check for FALSE in case of an error.

注释Note:

socket_write() does not necessarily write all bytes from the given buffer. It's valid that, depending on the network buffers etc., only a certain amount of data, even one byte, is written though your buffer is greater. You have to watch out so you don't unintentionally forget to transmit the rest of your data.

参见Here we have the same function to write a socket but with improved performance.

If the messager are not larger, they will be written entirely with a single socket_write() call. And is not needed to call the substr() function for the first bucle.

$st="Message to sent";

$length = strlen($st);

while (tr

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值