想請問sem_get裡的$autoRelease 和 sem_release() 釋放的是一樣的東西嗎?
因為小弟測試
//Semaphore properties
$key = 123456;
$max = 1;
$permissions = 0666;
$autoRelease = 1;
//Open a new or get an existing semaphore
$semaphore = sem_get($key, $max, $permissions, $autoRelease);
if(!$semaphore) {
echo "Failed on sem_get().\n";
exit;
}
//Try to aquire the semaphore.
for($i = 0; $i < 2; $i++) {
echo "\nAttempting to acquire semaphore...\n";
sem_acquire($semaphore);
echo "Aquired.\n";
echo "Enter some text: ";
$handler = fopen("php://stdin", "r");
$text = fgets($handler);
fclose($handler);
sem_release($semaphore);
echo "Got: $text \n";
}
請看文件:
https://www.php.net/manual/en/function.sem-get.php
autoRelease是在REQUEST結束時自動釋放,並不是說在你程式內某個地方會釋放。
建議你仔細看一下操作semaphore的四個函數:
https://www.php.net/manual/en/book.sem.php