Answer the question
In order to leave comments, you need to log in
Lazy creation of files in PHP (Python)?
There is a system that keeps logs using Zend_Log_Writer_Stream, messages are written to files.
When creating a Zend_Log_Writer_Stream, you need to pass a link to the file resource, that is, the file needs to be created - but not the fact that the system will issue messages that will be logged.
Therefore, there is a bunch of empty files.
Is there a mechanism for delayed file creation in PHP (for Python is also relevant) - that is, the file will be created only when writing to it begins and will not be created if there is no writing to it.
Answer the question
In order to leave comments, you need to log in
Let's talk about PHP. As far as I know, fopen opens a handle and creates a file accordingly. And if you do not call fopen, but implement it at a higher level, i.e. intercept the write operation and check if the file is open. If not open, then open. In general, I would inherit from Zend_Log_writer_Stream and add what I need.
In php / python there is a wonderful thing called OOP, with its help you can create an object, inherit from (in this case) Zend_Log_Writer_Stream and, oddly enough, override the necessary methods, replacing it with the expected logic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question