Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\System::writeFile(string $filename, string $fileContent, int $flags): bool
The absolute filepath where to write contents to. Including any file extension if needed. The file will be created if it does not exist, make sure you have the correct permissions.
The content to be written to the file as a string. The maximum writeable content is 4M.
The default flag is to clear the current contents and overwrite the file if it exists. But you can use FILE_APPEND
to append contents to the end of the file.
Returns true
when successful and false
when not.
Write string content into a file.
This method will immediately return false
if an error occurs.
Note: Consider using coroutine hooks instead so you can easily use native PHP read and write functions.
<?php
Co\run(function()
{
$filename = __DIR__ . "/test.txt";
$result = Co\System::writeFile($filename, "Hello World - from Swoole!\n");
var_dump($result);
});