라이브러리 업데이트 catfan/medoo 추가
This commit is contained in:
+3
-3
@@ -79,12 +79,12 @@ class FlockStore implements StoreInterface
|
||||
|
||||
// Silence error reporting
|
||||
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
|
||||
if (!$handle = fopen($fileName, 'r')) {
|
||||
if (!$handle = fopen($fileName, 'r+') ?: fopen($fileName, 'r')) {
|
||||
if ($handle = fopen($fileName, 'x')) {
|
||||
chmod($fileName, 0444);
|
||||
} elseif (!$handle = fopen($fileName, 'r')) {
|
||||
} elseif (!$handle = fopen($fileName, 'r+') ?: fopen($fileName, 'r')) {
|
||||
usleep(100); // Give some time for chmod() to complete
|
||||
$handle = fopen($fileName, 'r');
|
||||
$handle = fopen($fileName, 'r+') ?: fopen($fileName, 'r');
|
||||
}
|
||||
}
|
||||
restore_error_handler();
|
||||
|
||||
+9
-3
@@ -64,8 +64,14 @@ class SemaphoreStore implements StoreInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$resource = sem_get(crc32($key));
|
||||
$acquired = sem_acquire($resource, !$blocking);
|
||||
$keyId = crc32($key);
|
||||
$resource = sem_get($keyId);
|
||||
$acquired = @sem_acquire($resource, !$blocking);
|
||||
|
||||
while ($blocking && !$acquired) {
|
||||
$resource = sem_get($keyId);
|
||||
$acquired = @sem_acquire($resource);
|
||||
}
|
||||
|
||||
if (!$acquired) {
|
||||
throw new LockConflictedException();
|
||||
@@ -86,7 +92,7 @@ class SemaphoreStore implements StoreInterface
|
||||
|
||||
$resource = $key->getState(__CLASS__);
|
||||
|
||||
sem_release($resource);
|
||||
sem_remove($resource);
|
||||
|
||||
$key->removeState(__CLASS__);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Lock\Tests\Store;
|
||||
|
||||
use Symfony\Component\Lock\Key;
|
||||
use Symfony\Component\Lock\Store\SemaphoreStore;
|
||||
|
||||
/**
|
||||
@@ -29,4 +30,31 @@ class SemaphoreStoreTest extends AbstractStoreTest
|
||||
{
|
||||
return new SemaphoreStore();
|
||||
}
|
||||
|
||||
public function testResourceRemoval()
|
||||
{
|
||||
$initialCount = $this->getOpenedSemaphores();
|
||||
$store = new SemaphoreStore();
|
||||
$key = new Key(uniqid(__METHOD__, true));
|
||||
$store->waitAndSave($key);
|
||||
|
||||
$this->assertGreaterThan($initialCount, $this->getOpenedSemaphores(), 'Semaphores should have been created');
|
||||
|
||||
$store->delete($key);
|
||||
$this->assertEquals($initialCount, $this->getOpenedSemaphores(), 'All semaphores should be removed');
|
||||
}
|
||||
|
||||
private function getOpenedSemaphores()
|
||||
{
|
||||
$lines = explode(PHP_EOL, trim(`ipcs -su`));
|
||||
if ('------ Semaphore Status --------' !== $lines[0]) {
|
||||
throw new \Exception('Failed to extract list of opend semaphores. Expect a Semaphore status, got '.implode(PHP_EOL, $lines));
|
||||
}
|
||||
list($key, $value) = explode(' = ', $lines[1]);
|
||||
if ('used arrays' !== $key) {
|
||||
throw new \Exception('Failed to extract list of opend semaphores. Expect a used arrays key, got '.implode(PHP_EOL, $lines));
|
||||
}
|
||||
|
||||
return (int) $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user