Bug #75538 [Com]: stream_set_blocking() always returning false for files on windows
| From: | mattficken@php.net | Date: | Tue, 23 Jan 2018 02:53:13 +0000 |
| Subject: | Bug #75538 [Com]: stream_set_blocking() always returning false for files on windows | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213670@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
Comment by: mattficken@php.net
Reported by: samuel dot chemla at orange dot com
Summary: stream_set_blocking() always returning false for
files on windows
Status: Open
Type: Bug
Package: Streams related
Operating System: Windows
PHP Version: 7.1.11
Block user comment: N
Private report: N
New Comment:
stream_set_blocking() for local files can't be supported on Windows.
I have updated the documentation notes to state that.
This bug can probably be closed now.
Previous Comments:
------------------------------------------------------------------------
[2017-11-22 10:04:39] samuel dot chemla at orange dot com
Hi,
Thanks for your answer.
I didn't realize the implication of this, and I understand it's not a priority.
I'm not C developper, but I would be happy to help on PHP side (testing?)...
Maybe we should at least update the doc to mention that non blocking file acces cannot (yet :-)) be
guaranteed.
------------------------------------------------------------------------
[2017-11-21 15:01:33] ab@php.net
Thanks for the further explanation. With reactphp - yep, the topic was discussed at least with Bob
several times. However it regards more to standard file descriptors and pipes. Regular files are a
different matter.
What i was basically asking for was a bare implementation in PHP as a show case to evaluate
crossplatform. A flag being true/false is a bit insufficient :) Regular files are always available.
The I/O performance depends on quite some factors like caching, compression, encryption, etc. Libs
like libeven or libuv use also threading besidses the libc APIs. Just by changing a flag passed to
the C API likely won't guarantee anything. Even if done, the system can still decide to go
synchronously. An option here could be to cache those files in RAM, if possible.
So in first place - it is barely a bug in PHP, disregard the OS. The socket APIs support
non-blocking crossplatform. It might be for sure a significant chunk of work to spread this onto
regular files, standard descriptors and pipes. For what it matters, I'd be not really convinced
ATM it is worth and specially is possible without significant userspace API rework :( Perhaps libuv
and other bindings are a worthy option in this regard. At the current stage, even if the
non-blocking flag can be changed on some platforms, it doesn't guarantee non-blocking with the
regard to possible obstacles.
Thanks.
------------------------------------------------------------------------
[2017-11-21 10:16:54] samuel dot chemla at orange dot com
I made a mistake in my previous comment, you must read
array(9) {
...
'blocked' =>
bool(false)
...
}
(I copied/pasted the result without "n" mode)
------------------------------------------------------------------------
[2017-11-21 09:06:54] samuel dot chemla at orange dot com
Hi,
I'm building a server with https://github.com/reactphp/socket.
This server accepts connection from many clients and stream files to them (or receive files from
them).
As it handles all clients connections in one loop, all the code must be non blocking to achieve
optimal performance.
The most straightforward way to serve files is then to use https://github.com/reactphp/stream with a fopen()
resource, configured in a non blocking mode.
By the way react/stream doc says fopen() may block, but I see a non documented "n" mode
when using fopen (see https://github.com/php/php-src/blob/2283b6ff534e173bc56dc73137fedd19f37fc979/main/streams/plain_wrapper.c#L105)
if (strchr(mode, 'n')) {
flags |= O_NONBLOCK;
}
It actually works on linux, but not on windows.
$fileRes = fopen("bar.txt", 'wbn');
if ($fileRes === false) {
throw new Exception();
}
var_dump(stream_get_meta_data($fileRes));
will return :
array(9) {
...
'blocked' =>
bool(true)
...
}
(Maybe I should file another report on php documentation for this?)
https://github.com/reactphp/filesystem offers a
non blocking filesystem acces, but it seems very experimental, complex, and require eio extention or
create processes to read files.
I was looking for a simple solution with pure php (and fopen)
------------------------------------------------------------------------
[2017-11-20 19:36:47] ab@php.net
Thanks for the report. Could you give an extended example in PHP on the topic you've mentioned?
Thanks
------------------------------------------------------------------------
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