Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 25.x
Latest version:
pecl install openswoole-25.2.0
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 = swoole\mmap::open($file, 8192);
fwrite($fp, "hello world\n");
fwrite($fp, "hello swoole\n");
fflush($fp);
fclose($fp);
Swoole\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.