PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Networking » Net_Socket » Bug #980

Block write works better on Windows XP

Details

Submitted2004-03-09 13:18 UTC
Fromash at bigfoot dot de
Assignedchagenbu
StatusClosed
PackageNet_Socket
PHP Version5.0.0b4 (beta4)
OSWindows NT HAL 5.1 build 2600
Roadmaps(Not assigned)

Comments

[2004-03-09 13:18 UTC] ash at bigfoot dot de

Description:
------------
I tried to send big emails with PEAR Mail, but there always occured this, regardless of isBlocking() = TRUE or FALSE:

PHP Notice: fputs(): send of 8192 bytes failed with errno=0
Resource temporarily unavailable.

This seemed to be WinSock error 10035: WSAEWOULDBLOCK, so I changed the write method to send blocks of data.

The PHP Notice now comes for every call of fwrite, but the mail can be send. An @ before fwrite even let the PHP Notices disappear ;-)

Keep up the good work,
René

Reproduce code:
---------------
function write($data, $blocksize = 8192) {
if (is_resource($this->fp)) {
$pos = 0;
$size = strlen($data);
while($pos < $size) {
$written = fwrite($this->fp, substr($data, $pos, $blocksize), $blocksize);
if(FALSE === $written)
return FALSE;
$pos += $written;
}
return $pos;
}
return $this->raiseError("not connected");
}

[2004-04-04 03:33 UTC] chris at lodesys dot com

Ran into the same problem with 5.0.0RC1. Tried René's patch, which helped, but still having problems with the large $blocksize. Changed the blocksize & modified the fwrite call. Now able to send large PDF files as attachments without errors. Running Apache 1.3.28 & PHP/5.0.0RC1 under Windows 2000 SP3.

My version of the patch is as follows...

function write($data, $blocksize = 1280) {
if (is_resource($this->fp)) {
$pos = 0;
$size = strlen($data);
while($pos < $size) {
@$written = fwrite($this->fp, substr($data, $pos, $blocksize));
if(FALSE === $written)
return FALSE;
$pos += $written;
}
return $pos;
}
return $this->raiseError("not connected");
}

Not pretty, but it works.