ConFoo Montreal 2026: Call for Papers

Voting

: min(six, seven)?
(Example: nine)

The Note You're Voting On

Davide Renzi
15 years ago
Race conditions happen on an heavy load server when more than one thread tries to execute memcache_add.
For example if thread A and thread B try to save the same key you can test that sometimes both return TRUE.
To have the right behaviour you can verify that the correct value is in the assigned key:

<?php
function memcache_safeadd(&$memcache_obj, $key, $value, $flag, $expire)
{
if (
memcache_add($memcache_obj, $key, $value, $flag, $expire))
{
return (
$value == memcache_get($memcache_obj, $key));
}
return
FALSE;
}
?>

<< Back to user notes page

To Top