lfbn / file-get-contents-proxy
一个围绕file_get_contents的代理,为他提供了额外功能。
v0.0.1
2020-03-22 16:04 UTC
Requires
- php: 7.3.8
Requires (Dev)
- phpspec/phpspec: ^6.1
- symfony/var-dumper: ^5.0
This package is not auto-updated.
Last update: 2024-10-01 12:39:44 UTC
README
围绕file_get_contents提供额外功能的代理。
安装
使用composer安装该包
composer require "lfbn/file-get-contents-proxy"
为什么使用这个?
使用这个包,你可以使用file_get_contents来获取文件内容,并使这个内容在内存中可缓存。
这样,你就有了这个代理围绕file_get_contents提供的额外酷炫功能。
使用方法
一次性获取文件内容
如果你只需要获取一次文件内容,那么你不需要做任何不同的操作。只需像平时一样使用file_get_contents即可!
<?php $content = file_get_contents('some-file-name.txt');
多次获取文件内容
如果你想利用这个包,并且需要多次获取文件内容,那么你可以使用内存缓存。
<?php use FileGetContentsProxy\FileGetContentsProxy; $fileProxy = new FileGetContentsProxy('some-file-name.txt'); // It will be obtained from the file, and then, saved in memory. $content = $fileProxy->memoryCacheGet(); // It will be obtained from the memory cache. $cachedContent = $fileProxy->memoryCacheGet();
在之间你可以直接请求,不使用缓存
<?php $newContent = $fileProxy->directGet();