Skip to content

Instantly share code, notes, and snippets.

@k1LoW
Created July 18, 2009 23:52
Show Gist options
  • Save k1LoW/149743 to your computer and use it in GitHub Desktop.
Save k1LoW/149743 to your computer and use it in GitHub Desktop.
<?php
//http://buyukliev.blogspot.com/2007/08/no-more-socket-trouble-in-php.html
function fullread ($sd, $len) {
$ret = '';
$read = 0;
while ($read < $len && ($buf = fread($sd, $len - $read))) {
$read += strlen($buf);
$ret .= $buf;
}
return $ret;
}
function fullwrite ($sd, $buf) {
$total = 0;
$len = strlen($buf);
while ($total < $len && ($written = fwrite($sd, $buf))) {
$total += $written;
$buf = substr($buf, $written);
}
return $total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment