SplFileStream
文件資源流數據操作
相關class位置
- SplFileStream
-
namespace
:EasySwoole\Spl\SplFileStream
-
SplFileStream相關方法
方法名稱 | 參數 | 說明 |
---|---|---|
__construct | $file,$mode = 'c+' | 初始化資源和讀寫操作 |
lock | $mode = LOCK_EX | 文件鎖定 |
unlock | $mode = LOCK_UN | 釋放鎖定 |
SplFileStream類繼承SplStream,其他相關方法參考SplStream。
基本使用
<?php
/**
* Created by PhpStorm.
* User: root
* Date: 19-7-2
* Time: 上午10:25
*/
require_once 'vendor/autoload.php';
$fileStream = new \EasySwoole\Spl\SplFileStream('./test.txt');
$type = $fileStream->getMetadata('stream_type');
var_dump($type);
/**
* 輸出結果過:
* string(5) "STDIO"
*/
$fileStream = new \EasySwoole\Spl\SplFileStream('./test.txt');
$lock = $fileStream->lock();
var_dump($lock);
/**
* 輸出結果過:
* bool(true)
*/
$fileStream = new \EasySwoole\Spl\SplFileStream('./test.txt');
$unlock = $fileStream->unlock();
var_dump($unlock);
/**
* 輸出結果過:
* bool(true)
*/