Write to a File in PHP
PHPUse file_put_contents with LOCK_EX for an atomic write.
<?php
declare(strict_types=1);
$lines = ['alpha', 'beta', 'gamma'];
file_put_contents(
'out.txt',
implode(PHP_EOL, $lines) . PHP_EOL,
LOCK_EX
);
Use file_put_contents with LOCK_EX for an atomic write.
<?php
declare(strict_types=1);
$lines = ['alpha', 'beta', 'gamma'];
file_put_contents(
'out.txt',
implode(PHP_EOL, $lines) . PHP_EOL,
LOCK_EX
);