php / php/php-src

Exclusive locks are not supported for this stream `php://stdout`

Open
#13,777 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Category: Streams OS: Windows Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

I wonder why the file_put_contents emitts a Exclusive locks are not supported for this stream error and putting the very same stream into stream_supports_lock does not return false, but also errors.

The following code:

<?php

var_dump(stream_supports_lock("php://stdout"));

file_put_contents(
    "php://stdout",
    "x",
    FILE_APPEND | LOCK_EX,
);

Resulted in this output:

$ php test.php 
PHP Fatal error:  Uncaught TypeError: stream_supports_lock(): Argument #1 ($stream) must be of type resource, string given in C:\dvl\Workspace\phpunit\test.php:3
Stack trace:
#0 C:\dvl\Workspace\phpunit\test.php(3): stream_supports_lock()
#1 {main}
  thrown in C:\dvl\Workspace\phpunit\test.php on line 3

Fatal error: Uncaught TypeError: stream_supports_lock(): Argument #1 ($stream) must be of type resource, string given in C:\dvl\Workspace\phpunit\test.php:3
Stack trace:
#0 C:\dvl\Workspace\phpunit\test.php(3): stream_supports_lock()
#1 {main}
  thrown in C:\dvl\Workspace\phpunit\test.php on line 3

But I expected this output instead:

$ php test.php 
bool(false)
PHP Warning:  file_put_contents(): Exclusive locks are not supported for this stream in C:\dvl\Workspace\phpunit\test.php on line 5

Warning: file_put_contents(): Exclusive locks are not supported for this stream in C:\dvl\Workspace\phpunit\test.php on line 5

might be a windows only error, because 3v4l.org does not report the same error
https://3v4l.org/98p6T

PHP Version
$ php -v
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:35) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
Operating System

windows11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example on Windows with PHP 8.2.12 and compare stream_supports_lock("php://stdout") with file_put_contents(..., FILE_APPEND | LOCK_EX). Check the behavior against the expected boolean result and warning, then verify the same case no longer raises a TypeError and still reports unsupported exclusive locks.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.