- $temp = get_temppath();
- $locks = [];
- foreach (glob(sprintf('%s/%s*.sem', $temp, $prefix)) as $lock) {
- $lock = pathinfo($lock, PATHINFO_FILENAME);
- if(sem_get(self::semaphoreKey($lock))) {
- $locks[] = $lock;
+ // We can just return our own semaphore keys, since we don't know
+ // the state of other semaphores, even if the .sem files exists
+ $keys = array_keys(self::$semaphore);
+
+ if (empty($prefix)) {
+ return $keys;
+ } else {
+ $result = [];
+
+ foreach ($keys as $key) {
+ if (strpos($key, $prefix) === 0) {
+ array_push($result, $key);
+ }