windows 致命错误:调用未定义的函数 sem_get()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5251251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined function sem_get()
提问by Adam
I'm new to PHP and I'm trying to run code I got from someone else on my Windows development machine. I installed PHP 5 and Apache 2.2, but when I try to run it I get the error:
我是 PHP 新手,我正在尝试在我的 Windows 开发机器上运行我从其他人那里获得的代码。我安装了 PHP 5 和 Apache 2.2,但是当我尝试运行它时出现错误:
Fatal error: Call to undefined function sem_get()
The line it's being thrown from is:
它被抛出的行是:
private function UpdateCounter($semkey, $memkey, $count)
{
$sem_h = sem_get($semkey, 1);//this line is the problem
...
}
回答by Pascal MARTIN
The sem_get()
function is provided by the Semaphore, Shared Memory and IPCcomponent.
该sem_get()
功能由Semaphore、Shared Memory 和 IPC组件提供。
Quoting the introductionof it's manual section :
引用它的手册部分的介绍:
This extension is not available on Windows platforms.
此扩展在 Windows 平台上不可用。
回答by falsarella
I don't know if that will work as expected, but I found a workaround for sem_get on Windows:
我不知道这是否会按预期工作,但我在 Windows 上找到了sem_get的解决方法:
if (!function_exists('sem_get')) {
function sem_get($key) {
return fopen(__FILE__ . '.sem.' . $key, 'w+');
}
function sem_acquire($sem_id) {
return flock($sem_id, LOCK_EX);
}
function sem_release($sem_id) {
return flock($sem_id, LOCK_UN);
}
}
Also, I needed ftok on Windowstoo:
另外,我也需要在 Windows 上使用ftok:
if( !function_exists('ftok') )
{
function ftok($filename = "", $proj = "")
{
if( empty($filename) || !file_exists($filename) )
{
return -1;
}
else
{
$filename = $filename . (string) $proj;
for($key = array(); sizeof($key) < strlen($filename); $key[] = ord(substr($filename, sizeof($key), 1)));
return dechex(array_sum($key));
}
}
}