| 18 | | flock($fp, LOCK_EX); |
| 19 | | // check AGAIN after we get the lock |
| 20 | | if (!xcache_isset("abc_data", $post_check_ttl)) { |
| 21 | | mysql_query .... and get $data |
| 22 | | xcache_set("cache", $data, 120); |
| 23 | | fclose($fp); |
| 24 | | return $data; |
| 25 | | } |
| 26 | | else { |
| 27 | | fclose($fp); |
| | 18 | // only one worker update it and other keep on reading, if it's in post-check time |
| | 19 | $nb = xcache_isset($name) ? 0 : LOCK_NB; |
| | 20 | if (flock($fp, LOCK_EX | $nb)) { |
| | 21 | // check AGAIN after we get the lock |
| | 22 | if (!xcache_isset($name, $post_check_ttl)) { |
| | 23 | mysql_query .... and get $data |
| | 24 | xcache_set($name, $data, 120); |
| | 25 | fclose($fp); |
| | 26 | return $data; |
| | 27 | } |
| | 28 | else { |
| | 29 | fclose($fp); |
| | 30 | } |