[PEAR-BUG] Bug #18618 [Asn]: Incorrect CHUNK_SIZE

[email protected]
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=18618&edit=1

 ID:               18618
 Updated by:       [email protected]
 Reported By:      andy at fud dot org dot nz
 Summary:          Incorrect CHUNK_SIZE
 Status:           Assigned
 Type:             Bug
 Package:          Crypt_GPG
 Operating System: BSD/Linux
 Package Version:  SVN
 PHP Version:      Irrelevant
 Assigned To:      gauthierm
 Roadmap Versions: 
 New Comment:

Andy, thanks for your detailed report.

When developing the file streaming operations for Crypt_GPG I tested a
lot using 
strace to see what the buffer size used by PHP is. It seems PHP always
reads in 8k 
chunks no matter what chunk size you specify. If you specify 4k chunks,
PHP reads 
one 8k chunk and the next read comes from an internal buffer in PHP.

Of course, this may be different for writes.

Your description certainly sounds correct and I will have to do more
testing to 
verify PHP itself works properly.


Previous Comments:
------------------------------------------------------------------------

[2011-06-20 17:20:21] gauthierm

-:            [email protected]
+:            andy at fud dot org dot nz
-Assigned To:
+Assigned To: gauthierm


------------------------------------------------------------------------

[2011-06-20 17:19:09] gauthierm

Description:
------------
"POSIX.1-2001 says that write(2)s of less than PIPE_BUF bytes must be
atomic: the output data is written to the pipe as a contiguous
sequence.
Writes of more than PIPE_BUF bytes may be non-atomic: the kernel may
interleave the data with data written by other processes."

Most operating systems have PIPE_BUF as 4096 bytes. Setting CHUNK_SIZE
to
8192 may cause php to do two 4k writes which can cause Crypt_GPG to
hang
forever.

It hangs because $fdInput is returned as writable by stream_select(),
the
first 4k write succeeds (fully or partially) but because php will try
to
write the next 4k chunk it hangs as the fd is full and hasn't beed
re-selected to test if it can be written.

The other option is to set all file descriptors as non-blocking using
stream_set_blocking(), the code correctly increments the buffers for
the
actual amount written/read.

This will also fix bug 18526

------------------------------------------------------------------------


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=18618&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.