本文整理汇总了PHP中SplFileObject::fstat方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::fstat方法的具体用法?PHP SplFileObject::fstat怎么用?PHP SplFileObject::fstat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::fstat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeHistory
/**
* Function that writes history to the uncompiled history-file.
* History-files are "uncompiled" before Hicurl::compileHistory has been called on them, which generates a
* history-file of cosed state.
* In its uncompiled state its structure is as follows:
* (historyData without closing bracket and brace)+(tempHistoryData)+(sizeOfTempHistoryData)
* historyData is the following json-object: {"pages":[]}
* But in the uncompiled file it is without the closing bracket+brace as stated above. Each element in its
* pages-array is the following:<pre>
* { "formData"://this is present if it was a POST-request, and will contain the sent form-data
* ,"name"://a name-string for the page that will be shown in the history-viewer. Set via historyData>name
* ,"parentIndex": int//may hold an pointing to an index of another page in the pages-array. This will then be
* shown in the tree-view of the history-viewer. This is set up with loadSingle>historyData>id/parentId
* ,"customData": //contains what was passed to customData-parameter of the load method if anything
* ,"exchanges": [//An array of request&response pairs. Usually this will only contain one
* //element but more will be added for each failed request
* {
* "error": false if no error, otherwise an explanation of the error
* "content": the content of the page sent from the server
* "headers": ...and the headers
* }
* ...
* ]
* }
* </pre>
* @param SplFileObject $historyFileObject
* @param string $data A undecoded page-object, explained in the description of this method.
* @param array $settings
* @param array $historyData*/
private static function writeHistory($historyFileObject, $data, $settings, $historyData)
{
if (!isset($historyFileObject)) {
$historyFileObject = new SplFileObject($settings['history'], 'c+');
}
$historyFileObject->flock(LOCK_EX);
//check if the historyFile is empty. we don't have to check for file-existence because it will always
//have been created by now byt simply creating the SplFileObject
if (!$historyFileObject->fstat()['size']) {
$dataPrefix = '{"pages":[';
$historyFileTempData = ['numPages' => 0, 'idIndices' => []];
} else {
$dataPrefix = ',';
$tempDataSize = Hicurl::seekHistoryFileTempData($historyFileObject);
$historyFileTempData = json_decode($historyFileObject->fread($tempDataSize), true);
$historyFileObject->fseek(-4 - $tempDataSize, SEEK_END);
}
if (isset($historyData['id'])) {
$historyFileTempData['idIndices'][$historyData['id']] = $historyFileTempData['numPages'];
}
if (isset($historyData['parentId'])) {
$data['parentIndex'] = $historyFileTempData['idIndices'][$historyData['parentId']];
}
++$historyFileTempData['numPages'];
$historyFileObject->fwrite($dataPrefix . json_encode($data));
$tempDataSize = $historyFileObject->fwrite(json_encode($historyFileTempData));
$historyFileObject->fwrite(pack('N', $tempDataSize));
$historyFileObject->flock(LOCK_UN);
}