Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow ini_set('error_log',...) with in-memory stream #17817

Open
staabm opened this issue Feb 15, 2025 · 3 comments
Open

allow ini_set('error_log',...) with in-memory stream #17817

staabm opened this issue Feb 15, 2025 · 3 comments

Comments

@staabm
Copy link
Contributor

staabm commented Feb 15, 2025

Description

calling ini_set('error_log', $logger) seems to expect $logger to be a filesystem path (or a magic identifer like "syslog").

is it possible to pass in a memory stream?

use-case: in phpunit we want to capture all output a possible code beeing tested might write into error_log.
I have implemented this feature with a tmpfile() in sebastianbergmann/phpunit#6118 but IMO it would be cleaner and more efficient (no filesystem IO) if I could pass in a memory stream like php://memory or php://temp:

        $stream = fopen('php://temp', 'rw');
        $errorLogPrevious = ini_set('error_log', $stream);
@bwoebi
Copy link
Member

bwoebi commented Feb 16, 2025

ini_set() generally works on strings. I don't think this should change.
However it would be probably nice to introduce and accept custom named php://temp/name:foo streams, which are essentially in-request virtual streams which are stored by their name, which are also usable with php internals (like error_log).

@staabm
Copy link
Contributor Author

staabm commented Feb 16, 2025

Yes.. I was also thinking whether a separate method like set_error_log_handler or similar should be introduced so we don't need to change the ini_set signature

@mvorisek
Copy link
Contributor

mvorisek commented Feb 17, 2025

ini_set() generally works on strings. I don't think this should change.

Not sure if this is supported now, but if VFS is already supported, user can (quite easily) register custom scheme handler.

However it would be probably nice to introduce and accept custom named php://temp/name:foo streams, which are essentially in-request virtual streams which are stored by their name, which are also usable with php internals (like error_log).

Does opened path have to match the given one? If not, the in-memory-path can be some unique string obtainable via https://www.php.net/manual/en/function.stream-get-meta-data.php and uri key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants