Semaphore Warning: semop() failed in release_sysvsem_sem for key
Denne kode skulle gerne bevirke at kun 1 tråd/bruger kommer igennem af gangen.Denne fejl kommer desværre bare op hvis 2 kører den samtidigt.
"Warning: semop() failed in release_sysvsem_sem for key 0x1: Invalid argument in Unknown on line 0"
Er der nogen der ved om jeg har lavet en fejl, eller hvad der ellers måtte være galt.
//instantiate shared memory and semaphore
$MEMSIZE = 2048;// size of shared memory to allocate
$SEMKEY = 1; // Semaphore key
$SHMKEY = 2; // Shared memory key
//instantiate finished
$sem_id = sem_get($SEMKEY, 1); // get the information about semaphore, if this does not happen, page reloads
if ($sem_id === false)
{
?><script language="JavaScript">
window.location.reload(true)
</script><?
}
else
//echo "Got semaphore $sem_id.\n";
// Accuire semaphore
if (! sem_acquire($sem_id)) // try to get the semaphore, if the semaphore is allready taken, page reloads
{
sem_remove($sem_id);
sleep(3);
?><script language="JavaScript">
window.location.reload(true)
</script><?
}
else
$shm_id = shm_attach($SHMKEY, $MEMSIZE); // get information about shared memory access, if problem, page reloads
if ($shm_id === false)
{
sem_remove($sem_id);
sleep(3);
?><script language="JavaScript">
window.location.reload(true)
</script><?
}
else
$var1 = 0;
$var1 = shm_get_var ($shm_id, 1); // read information about shared memory
echo ("Tidspunktet for sidste kørsel: ". $var1."<br>");
$timestamp = time();
$date_time_array = getdate($timestamp);
$timestamp = mktime($date_time_array['seconds'], $date_time_array['minutes']);
$seconds = $date_time_array['seconds'];
$minutes = $date_time_array['minutes'];
if ($minutes < 10) //if there is less then 10 minutes in the hour put a zero in front
$minutes = "0".$minutes;
if ($seconds < 10) //if there is less then 10 seconds in the minute put a zero in front
$utime = $minutes."0".$seconds;
else
$utime = $minutes.$seconds;
if ($utime <= 4) //If the time has changed to a new hour and the utime is with in 4 seconds of this, page reloads.
{
sem_remove($sem_id);
sleep(2);
?><script language="JavaScript">
window.location.reload(true)
</script><?
exit;
}
$seconds_old = $var1{2}.$var1{3};
if ($seconds < 4 && $seconds_old > 56) //if there is a change in the minute 40 seconds is applied
$var1 = $var1 + 40;
if($var1)
{
$test = $unlocktime-$var1;
if ($test <= 4 && $test >=0) //If there is less then 4 seconds between the utime and var1(shm utime), page reloads
{
sem_remove($sem_id);
sleep(2);
?><script language="JavaScript">
window.location.reload(true)
</script><?
exit;
}
}
// Write variable 1
if (!shm_put_var($shm_id, 1, "$unlocktime")) //try to write utime to shared memory. If not possible, page reloads
{
sem_remove($sem_id);
sleep(2);
?><script language="JavaScript">
window.location.reload(true)
</script><?
exit;
}
// Release semaphore
if (!sem_release($sem_id)) //try to release semaphore. if not possible, page reloads THIS IS BAD!!!
{
sem_remove($sem_id);
sleep(2);
?><script language="JavaScript">
window.location.reload(true)
</script><?
exit;
}