Bug #75538 [Csd]: stream_set_blocking() always returning false for files on windows

From: Date: Mon, 19 Nov 2018 09:20:36 +0000
Subject: Bug #75538 [Csd]: stream_set_blocking() always returning false for files on windows
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218036@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75538&edit=1

 ID:                 75538
 Updated by:         requinix@php.net
 Reported by:        samuel dot chemla at orange dot com
 Summary:            stream_set_blocking() always returning false for
                     files on windows
 Status:             Closed
 Type:               Bug
 Package:            Streams related
 Operating System:   Windows
 PHP Version:        7.1.11
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

> Can you provide a working example of non blocking file access on linux?
Feel free to submit a bug report on how stream_set_blocking() with a local file, on Linux, appears
to work when ultimately the operating system is not respecting the setting. Because that's not
what this report was about.


Previous Comments:
------------------------------------------------------------------------
[2018-11-19 09:02:20] samuel dot chemla at orange dot com

Well, in http://man7.org/linux/man-pages/man2/open.2.html:
>O_NONBLOCK or O_NDELAY
              When possible, the file is opened in nonblocking mode.
              Neither the open() nor any subsequent operations on the file
              descriptor which is returned will cause the calling process to
              wait.

              Note that this flag has no effect for regular files and block
              devices; 

"This flag has no effect for regular files".

I've done some tests on linux, reading files.
* stream_set_blocking($handle, false) return true, so i expected it to work.
* then i tries fread($handle, $length) with many different $length sizes, and fread always returned
the required length, event on a busy system, with a slow rotating drive
--> So I assume stream_set_blocking() do **not** work on linux either.

Am I wrong?
Can you provide a working example of non blocking file access on linux?

------------------------------------------------------------------------
[2018-11-16 17:06:57] requinix@php.net

> My understanding is that stream_set_blocking does *not* work for regular files, whatever the OS
> is.
Linux and BSD may or may not support it, but all seem to support setting the flag.

http://man7.org/linux/man-pages/man2/open.2.html
> When possible, the file is opened in nonblocking mode.
> Note that this flag has no effect for regular files and block devices

https://linux.die.net/man/2/open
> When possible, the file is opened in nonblocking mode.

https://www.freebsd.org/cgi/man.cgi?sektion=2&query=open
> O_NONBLOCK   do not block on open

But Windows' _open doesn't have a "_O_NONBLOCK" or other non-blocking flag.
https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx

In fact as far as I can tell, it doesn't have an fcntl (though winsock has something equivalent
for sockets?) or O_NONBLOCK flag anywhere. I think that's the problem: not that Windows
doesn't allow setting non-blocking on files but that it can't.

------------------------------------------------------------------------
[2018-11-16 13:54:36] samuel dot chemla at orange dot com

I'm reopening this because I think it requires clarification

------------------------------------------------------------------------
[2018-11-09 20:59:30] samel dot chemla at orange dot com

Hi!

I know this is an old topic, but I just saw the doc http://php.net/manual/en/function.stream-set-blocking.php
was updated with that note: "On Windows, this has no affect on local files. Non-blocking IO for
local files is not supported on Windows."

My understanding is that stream_set_blocking does *not* work for regular files, whatever the OS is.

Then if this is correct, then:
* the windows note should be removed from the documentation,
* this statement should be fixed: "This function works for any stream that supports
non-blocking mode (currently, regular files and socket streams)."
* stream_set_blocking() should return false, whatever the OS is. IE linux implementation should be
fixed because actually it returns true.

Can you clarify?
Regards.

------------------------------------------------------------------------
[2018-01-26 16:47:03] ab@php.net

Closing as per request. Thanks for documenting, Matt.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=75538


--
Edit this bug report at https://bugs.php.net/bug.php?id=75538&edit=1


Thread (13 messages)

« previous php.bugs (#218036) next »