我是PHP的新手,我正在尝试运行我在Windows开发机器上从其他人处获得的代码。我安装了PHP 5和Apache 2.2,但是当我尝试运行它时出现错误:
Fatal error: Call to undefined function sem_get()
它被抛出的线是:
private function UpdateCounter($semkey, $memkey, $count)
{
$sem_h = sem_get($semkey, 1);//this line is the problem
...
}
答案 0 :(得分:9)
答案 1 :(得分:6)
我不知道这是否会按预期工作,但我找到了workaround for sem_get on Windows:
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);
}
}
另外,我也需要ftok on Windows:
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));
}
}
}