Base::mutex PHP Method

mutex() public method

Create mutex, invoke callback then drop ownership when done
public mutex ( $id, $func, $args = NULL ) : mixed
$id string
$func callback
$args mixed
return mixed
    function mutex($id, $func, $args = NULL)
    {
        if (!is_dir($tmp = $this->hive['TEMP'])) {
            mkdir($tmp, self::MODE, TRUE);
        }
        // Use filesystem lock
        if (is_file($lock = $tmp . $this->get('SEED') . '.' . $this->hash($id) . '.lock') && filemtime($lock) + ini_get('max_execution_time') < microtime(TRUE)) {
            // Stale lock
            @unlink($lock);
        }
        while (!($handle = @fopen($lock, 'x')) && !connection_aborted()) {
            usleep(mt_rand(0, 100));
        }
        $out = $this->call($func, $args);
        fclose($handle);
        @unlink($lock);
        return $out;
    }