php文件写入txt,PHP: fwrite - Manual

Some people say that when writing to a socket not all of the bytes requested to be written may be written. You may have to call fwrite again to write bytes that were not written the first time. (At least this is how the write() system call in UNIX works.)

This is helpful code (warning: not tested with multi-byte character sets)

function fwrite_with_retry($sock, &$data)

{

$bytes_to_write = strlen($data);

$bytes_written = 0;

while ( $bytes_written < $bytes_to_write )

{

if ( $bytes_written == 0 ) {

$rv = fwrite($sock, $data);

} else {

$rv = fwrite($sock, substr($data, $bytes_written));

}

if ( $rv === false || $rv == 0 )

return( $bytes_written == 0 ? false : $bytes_written );

$bytes_written += $rv;

}

return $bytes_written;

}

Call this like so:

$rv = fwrite_with_retry($sock, $request_string);

if ( ! $rv )

die("unable to write request_string to socket");

if ( $rv != strlen($request_string) )

die("sort write to socket on writing request_string");

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值