创建假文件句柄
这可能是不可能的,但我想我应该四处打听,看看我是否错过了什么。我正在寻找一种使用需要文件指针句柄的函数而不需要编写实际文件的方法。
我知道我可以使用临时文件,执行操作,然后将文件读回输出缓冲区并删除该文件。然而,这意味着从写入磁盘到从磁盘读取的延迟。就我而言,如果我可以做类似的事情,那么速度和资源会好得多,
$tmp = createFakeFile();
fputscsv($tmp, array(/*** an array of csv fields ***/));
echo $tmp;
我怀疑这是否存在,但如果您曾经听说过做这样的事情的方法,我很想听听,
谢谢
This is probably impossible but i thought i would ask around and see if i missed something. What im looking for is a way of using functions that require file pointer handle without the need to write an actual file.
I know i could use a temporary file, do my operations then read the file back into the output buffer and delete the file. However this means latency from writing to disk then reading from the disk. It would be far better for speed and resources in my case if i could just do something like
$tmp = createFakeFile();
fputscsv($tmp, array(/*** an array of csv fields ***/));
echo $tmp;
I doubt this exists but if you've ever heard of a way of doing something like this i'd love to hear about it
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为此使用 php://memory 和 php://temp 包装文件。
引用:
http://php.net/manual/en/wrappers.php.php
You can use php://memory and php://temp wrapper files for this.
Cite:
http://php.net/manual/en/wrappers.php.php
确实有一种方法可以做到这一点:
stream_wrapper_register()
。
这个示例类应该做你想做的事情,它创建实际上只是保存在内存中的文件句柄。
话虽如此,
php://memory
在某种程度上,php://temp
。There is indeed a way to do it:
stream_wrapper_register()
.This example class should do what you want, it creates a file handle that is actually just held in memory.
Having said that, so does
php://memory
and to some degree,php://temp
.