Skip to content

BUG: locks not working as expected #14592

Open
@batata004

Description

@batata004

Description

The following code:

<?php
$arquivo_lock = fopen("test.txt","a");

if (flock($arquivo_lock,LOCK_EX|LOCK_NB)) { 
    echo "Yes";
} else {
    echo "No";
}

sleep(10);

fclose($arquivo_lock);
?>

Save the simple code above to the file test.php, for example. Now, in less than 10 seconds apart, open 2 (or more) tabs on your browser calling the file test.php and you will see every tab will show you Yes after some seconds. It should show Yes only on the first tab, all the other should return immediatly with No because I am using LOCK_NB flag.

This bug is pretty simple to reproduce and other people also confirmed it on Stackoverflow when I reported there.

PHP Version

8.x

Operating System

Confirmed at least on centos 9 stream and windows 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions