php include 来自 fifo(命名管道)文件的指令
我一直在寻找一种方法来使用使用 posix_mkfifo 创建的 fifo(命名管道)文件来使用“include”语句。由于我的期望很高,当我看到页面被阻止、等待我确信它永远不会发生的操作时,我感到非常沮丧。
所以...我的逻辑表明,由于“include”肯定使用某种“fopen”系列函数,并且 fifo 可以通过这种方式打开,我唯一要做的就是:创建一个,然后写入其中,也许保留资源在被包含之前一直处于活动状态,包含文件,关闭处理程序,删除文件。但当然不是那样的。我认为 include 以阻塞方式打开文件,这种行为是我的问题的原因。 在使用 c 中的 fifo 后,我注意到在非阻塞打开方法中,fifo 中的信息将被保留,直到读者决定读取它。我希望有同样的行为。
尽管我尝试打开另一个页面来写入同一个 fifo,以便读者可以继续,但这也注定会失败。此外,不仅页面不再响应,而且它也无法回答用户中止,因为我的会话被阻塞了几分钟,因为 session_start() 会告诉我不能被两个进程使用一次(我在这里的错误消息可能是错误的,我记得很清楚,并且我已经删除了测试文件。)
我的问题是是否有任何方法可以实现这种效果:包括使用 fifo。
到底, 为了回答所有关于我到底为什么要这样做的问题,我会说我的系统将自己置于真实代码和它的处理之间,目的是根据需要以动态方式修改它,完全可逆。为此,它需要读取原始文件,检查代码,在需要时进行更改,然后将其写入文件中,在新的“根”文件夹中,保留文件夹和文件层次结构,然后“包含”该文件。 目前,我将fifos的使用替换为真实文件的使用,但我需要过滤很多代码。 eval 虽然在我的函数中被过度使用,但并不是一个解决方案,因为它不保留当前目录和脚本名称,或任何特定于实际文件的内容,此外它对很多事情都非常明智,尤其是相对路径,并且php 语法的奇怪用法。所以我仍然坚持写文件。
因为系统是一个可怕的时间消耗者和一个糟糕的资源管理器,我最初的想法是写入更轻的 fifo,保存在内存中,易失性,并且真正为 IPC 的唯一目的而设计。
怀着敬意, 保罗
I was looking to find a way to use "include" statement using a fifo (named pipe) file created with posix_mkfifo. As my expectations were high I got very depressed to see the page blocked, waiting for an action that I was sure it won't ever happen.
So... my logic dictated that as "include" surely use some kind of "fopen"-family function, and fifos can be opened this way, my only thing to do was: to create one, then write in it, maybe keep the resource alive until it was included, include the file, close the handler, delete the file. But of course it was nothing like that. I suppose that include opens the file in a blocking manner and this behavior is the cause of my problem.
Having worked with fifos in c, I noticed that in a non-blocking open method the information in fifo is preserved until a reader decides to read it. I was hoping on the same behavior.
Although I tried to open another page to write to the same fifo, so that the reader can continue, that was bound to fail also. Furthermore, not only the page did not respond anymore, but it failed to answer to the user abort also, fact due to I had my sessions blocked for several minutes, as session_start() would tell me that there cannot be used by two processes at once ( I might be wrong here about the error message, I can remember well, and I have deleted the test files. )
My question is if there is any way to achieve this effect: of including using a fifo.
In the end,
to answer all the questions about why the hell am I doing this I will say that my system puts itself between the real code and it's processing with the purpose of modifying it on need in a dynamic manner, completely reversible. And for that it needs to read the original file, check the code, change it when it seems to and then write it in a file, in a new "root" folder, keep the folder and files hierarchy and then "include" the file.
At the moment, I replaced the use of fifos with the one of real files, but I need to filter a lot of code. And eval, although overused in my functions, is not a solution as it do not keep the current directory and the script name, or anything specific to an actual file, besides that it is very sensible with many things, especially with relative paths, and weird uses of php syntax. So I am still stuck with writing in files.
Because of that the system is a terrible time consumer and a bad resource manager, my original idea was to write in fifos that are more light, kept in memory, volatile, and really made for the only purpose of IPC.
With respect,
paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中所建议的,我将详细说明一下:编写您自己的流包装器,然后您可以将其注册在协议之上:
完成后,在您的
WrapCode
流包装器类中,您可以打开原始资源的流,然后透明地在文件上处理它。这将是即时的,因此您无需关心将文件存储在某个地方(但您仍然可以这样做)。PHP 手册提供了一个带有简单流包装类的示例 这显示了它是如何工作的。
As suggested in a comment, I'll elaborate it a bit: Write your own stream wrapper and then you can register it on top of a protocol:
That done, inside your
WrapCode
stream wrapper class, you can open a stream to the original resource and then process it on the file transparently. This would be on-the-fly, so you don't need to care about storing your files somewhere (but you still can do so).The PHP Manual offers an example with a simple stream wrapper class which shows how it works.