I have this minimal example for PHP 8.1:
<?php
ini_set('display_errors', 'on');
if(($fp = @fopen(__DIR__ . '/test.some', 'r+')) === false){
$fp = fopen(__DIR__ . '/test.some', 'c+');
}
flock($fp, LOCK_EX);
exec('eval `ssh-agent -s`', $output1, $resultCode1);
var_dump($output1, $resultCode1);
fclose($fp);
The problem is that when I run this script twice, then the second instance will block on the flock() function call, supposedly because the first one did not release the file lock.
When I exec() a different command instead of eval `ssh-agent -s`
, such as git --version
, then everything seems to work fine.
Does anyone know what the problem is? Is it a bug in PHP or my poor understanding of flock()?