我尝试在 php 上使用 semaphores 但无法使 sem_get() 函数正常工作。这是我的 PHP 代码:
<?php
$key = 123567;
$maxAcquire = 1;
$permissions = 0666;
$autoRelease = 1;
//it gives the error on the line below
$semaphore = sem_get($key, $maxAcquire, $permissions, $autoRelease);
sem_acquire($semaphore);
echo "hello world!";
sem_release($semaphore);
?>
当我尝试运行它时:
php semaphore.php
它打印此错误:
PHP Fatal error: Uncaught Error: Call to undefined function sem_get()
in /root/semaphore.php:8
Stack trace:
#0 {main}
thrown in /root/semaphore.php on line 8
我正在使用 PHP 7.0.3 (cli) 开发 Arch Linux。我想解决方案很简单,但我找不到解决方法。如果您能帮助我,我将不胜感激。谢谢。
最佳答案
对信号量的支持不是 php 的标准功能。
创建 php 二进制文件时,必须通过编译器 --enable-sysvsem
选项激活它。
关于PHP sem_get() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523382/