UCE Docs / file_put_contents

Signature

bool file_put_contents(String file_name, String content)

Parameters

file_name : file to write, resolved against the unit's directory
content : bytes to write (replaces any existing content)
return value : true on success

Writes content to a file, replacing whatever was there. The write takes an exclusive lock for the truncate-and-write, so concurrent writers are serialized and readers wait for it; you never manage locks yourself.

Example

file_put_contents("/tmp/doc-put.txt", "first");
file_put_contents("/tmp/doc-put.txt", "second");
print(file_get_contents("/tmp/doc-put.txt"), "\n");
Output
second