我想在我的 PHP 代码中使用信号量。我更新我的服务器的 PHP 版本,它通过命令行工作正常。当我尝试通过浏览器访问它时,出现错误:
Fatal error: Call to undefined function sem_get() in .../semaphore.php on line 8
代码如下:
<?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);
?>
即使它可以通过命令行工作,为什么它不能在浏览器上工作?是关于 apache 服务器 的吗?除了信号量,您对PHP 上的互斥 有什么建议吗?我希望数据库中的文本一次由一个用户编辑。谢谢。
最佳答案
Support for this functions are not enabled by default. To enable System V semaphore support compile PHP with the option --enable-sysvsem . To enable the System V shared memory support compile PHP with the option --enable-sysvshm . To enable the System V messages support compile PHP with the option --enable-sysvmsg .
您已使用 --enable-sysvsem
编译 PHP 以启用该功能。
最后,您可以使用 phpinfo()
函数验证信号量支持的状态。
更新 此外,OP 发现 Apache 使用的版本与控制台中使用的 PHP 版本不同。因此,浏览器和控制台的输出是不同的。
关于php - 无法在我的主机中使用 PHP sem_get() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35596240/