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
OpenSwoole provides the api to use mmap for files access. This is useful when multiple threads or processes accessing data in a read only fashion from the same file.
<?php
$file = __DIR__.'/data.dat';
$size = 8192;
if (!is_file($file)) {
file_put_contents($file, str_repeat("\0", $size));
}
$fp = OpenSwoole\mmap::open($file, 8192);
fwrite($fp, "hello world\n");
fwrite($fp, "hello OpenSwoole\n");
fflush($fp);
fclose($fp);
OpenSwoole\Mmap->open($file, $size = -1, $offset = 0)
Alias: function swoole_mmap->open($file, $size = -1, $offset = 0)
Map a file into memory and return a stream resource which can be used by PHP stream operations.