协程方式写入文件。
function Coroutine::writeFile(string $filename, string $fileContent, int $flags);
需要
2.1.2
或更高版本
$filename
为文件的名称,必须有可写权限,文件不存在会自动创建。打开文件失败会立即返回false$fileContent
为要写入到文件的内容,最大可写入4M$flags
为写入的选项,可以使用FILE_APPEND
表示追加到文件末尾,默认会清空当前文件内容写入成功返回true
,写入失败返回false
use Swoole\Coroutine as co;
$filename = __DIR__ . "/defer_client.php";
co::create(function () use ($filename)
{
$r = co::writeFile($filename,"hello swoole!");
var_dump($r);
});