swoole_mmap::open
�����ļ��ڴ�ӳ�䣬����ԭ�ͣ�
function swoole_mmap::open($file, $size = -1, $offset = 0);
- $file �����ļ����ƣ������Ǵ��ڵ��ļ�������ļ������ڽ��ᴴ��ʧ�ܡ�����ʹ��
file_put_contents����ʼ���ļ��� - $size ӳ�������Ĭ��Ϊ�����ļ��ij��ȣ�����ϵͳ�����ͬ�ȴ�С���ڴ档ע�ⲻҪ���Խ�����ϵͳ�ڴ�ߴ���ļ�����ӳ��
- $offset �ļ���ӳ����ʼλ�ã�Ĭ��Ϊ0
- ִ�гɹ�������һ��PHP��
stream��Դ����ʹ��PHP�ṩ����ʽ����������д����
�����ڴ�
- ��ȡ���ݣ�
fread��fgets - д�����ݣ�
fwrite��fputs - �ر��ڴ�ӳ�䣬
fclose���ײ���Զ�ִ��fflush������ͬ���������ļ� - ͬ�����ݣ�
fflush���ڴ��е�����д�뵽����
ʹ��ʾ��
$file = __DIR__.'/data';
$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);