我有这个错误
Call to undefined function sem_get()
它在 PHP 5.3.27、Apache/2.2.15 和 CentOS 上运行。
我找不到原因,而且我们有一个(几乎)设置相同的测试服务器,它工作正常(可能是不同的 PHP 扩展,因为我们也将此服务器与其他项目一起使用)。
我正在运行的测试如下:
<pre>
starts
<?
try {
echo "instance\n";
$mutex = new Mutex(633);
echo "Acquire \n";
$mutex->Acquire();
echo "\n\n Atomic magic \n\n";
echo "release \n";
$mutex->Release();
echo "null \n";
$mutex = null;
echo "end \n";
}
catch (Exception $e)
{
echo $e;
echo "\n<hr>\n";
var_dump(error_get_last());
}
Mutex 类如下:
<?php
class Mutex
{
protected $_Id;
protected $_SemId;
protected $_IsAcquired = false;
/**
* @param int $id Identifier of the Mutex, must be a number
*/
function __construct($id)
{
if (!is_int($id))
{
throw new Exception('The Mutex identifier must be a number');
}
$this->_Id = $id;
if (!($this->_SemId = sem_get($this->_Id, 1)))
{
throw new Exception('Error getting semaphore');
}
}
public function Acquire()
{
if (!sem_acquire($this->_SemId))
{
throw new Exception('Error acquiring semaphore');
}
$this->_IsAcquired = true;
}
public function Release()
{
if (!$this->_IsAcquired)
{
return;
}
if (!sem_release($this->_SemId))
{
throw new Exception('Error releasing semaphore');
}
$this->_IsAcquired = false;
}
}
?>
谢谢