<?php
function atomicWrite(string $path, string $contents, int $mode = 0644): bool {
$dir = dirname($path);
$tmp = tempnam($dir, '.atomic-');
if ($tmp === false) return false;
try {
if (file_put_contents($tmp, $contents, LOCK_EX) === false) return false;
chmod($tmp, $mode);
return rename($tmp, $path); // atomic on the same filesystem
} finally {
if (file_exists($tmp)) @unlink($tmp);
}
}
atomicWrite('/var/lib/myapp/state.json', json_encode(['ok' => true]));
Create a free account and build your private vault. Share publicly whenever you want.