Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\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 = OpenSwoole\Coroutine\System::writeFile($filename, "Hello World - from OpenSwoole!\n");
var_dump($result);
});