php - 无法在我的主机中使用 PHP sem_get() 函数

标签 php linux apache mutex dreamhost

我想在我的 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 上的互斥 有什么建议吗?我希望数据库中的文本一次由一个用户编辑。谢谢。

最佳答案

installation note提及:

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/

相关文章:

linux - "Thread.sleep(30000)"在 Windows 和 Linux 上的工作方式是否相同?

apache - 全新安装的 Sierra 上的 Homebrew Apache 无法使用奇怪的警告

django - 服务器滞后 - Django + mongodb + cronjob

PHP 错误 - 将用户表单插入数据库

php - 如果在登录页面(没有登录)中使用 Auth::logout() 会给出错误。拉拉维尔 5.5

php - 设置站点 : config settings/issues 的本地版本

c - 我们是否需要在收到来自 cond 变量的信号后解锁互斥锁?

php - IE 中的对象预期错误

android - 使用 linux convert 实用程序用空白填充图标

apache - 组件服务中的 Solr 显示已暂停且无法在 Windows 上启动