-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclusive locks are not supported for this stream php://stdout
#13777
Comments
turned differently: how to check a stream I can put into I tried Lines 498 to 502 in 79e4ca1
|
I can answer the first question: So |
On Windows then var_dump(stream_supports_lock(STDOUT)); // bool(true)
var_dump(flock(STDOUT, LOCK_EX)); // bool(false)
var_dump(flock(STDOUT, LOCK_SH)); // bool(false)
var_dump(file_put_contents("php://stdout", "x", FILE_APPEND | LOCK_EX,)); // bool(false) / Warning: file_put_contents(): Exclusive locks are not supported for this stream in php shell code on line 1 |
The discrepancy between php-src/main/streams/plain_wrapper.c Lines 733 to 735 in cf31332
i.e. this just always says that locking is supported for file descriptors. |
I don't think that it's possible to lock STDOUT on Windows (or any other console handle for that matter).
For Windows, the following might do: main/streams/plain_wrapper.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index fb2addb9e6..080f88a509 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -731,6 +731,13 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
}
if ((uintptr_t) ptrparam == PHP_STREAM_LOCK_SUPPORTED) {
+#ifdef PHP_WIN32
+ if (GetFileType((HANDLE) _get_osfhandle(fd)) == FILE_TYPE_CHAR) {
+ return -1;
+ } else {
+ return 0;
+ }
+#endif
return 0;
} That would cater to console handles and other character devices (e.g. LPT), but I assume that none of them is lockable (and certainly not with our current I don't quite understand "a portable way", though – isn't this a Windows only issue (at least it's tagged as such). |
As far as we know yes. What I mean is that we don't check whether something is lockable on other platforms too. Although the behaviour is observed on Windows, there can be other platforms that have similar issues. I looked for a portable (e.g. posix or standard C) solution but couldn't find one. |
Ah, right. That might be meaningless anyway, because even if general "lockability" would be supported, you can never know if the file can actually be locked with a certain operation ( |
Description
I wonder why the
file_put_contents
emitts aExclusive locks are not supported for this stream
error and putting the very same stream intostream_supports_lock
does not returnfalse
, but also errors.The following code:
Resulted in this output:
But I expected this output instead:
might be a windows only error, because 3v4l.org does not report the same error
https://3v4l.org/98p6T
PHP Version
Operating System
windows11
The text was updated successfully, but these errors were encountered: