katzgrau / KLogger

A Simple Logging Class For PHP
http://codefury.net/projects/klogger/
980 stars 284 forks source link

Warning: fwrite(): 38 is not a valid stream resource - only in lambda call #78

Closed s0me0ther closed 8 years ago

s0me0ther commented 8 years ago

PHP Version 5.6.3

For my actual project i use a mix of klein.php for routing and KLogger for filelogging.

The logger is instanced in general in the app handler, and available in the routing classes which call "klein" routes inside:

<?php

namespace Router\Routes;

class GetHostInformations extends Base{

    public function init() {
        $that = $this;

        $this->getLogger()->debug('works');

        $this->getRouter()->getKlein()->respond('GET', '/hello-world', function (
                \Klein\Request $request, 
                \Klein\Response $response, 
                \Klein\ServiceProvider $service, 
                \Klein\App $app) use (&$that) {

            $that->getLogger()->debug('not working..'); // doesn work
            $this->getLogger()->debug('not working..'); // doesn work either

            return "hello-world";
        });
    }
}

If i request this route, all log files will be written, instead of the debug logs in the lambda function of klein.

Instead i get following error:

Warning: fwrite(): 38 is not a valid stream resource in C:\xampp\htdocs\project\application\vendor\katzgrau\klogger\src\Logger.php on line 227

Fatal error: Uncaught exception 'RuntimeException' with message 'The file could not be written to. Check that appropriate permissions have been set.' in C:\xampp\htdocs\project\application\vendor\katzgrau\klogger\src\Logger.php:228

If i check the filehandle in klogger vendor, i dont see any errors, i everytime get:

Resource id #38

But if i check the handle via stream_get_meta_data it returns false on the lambda call.

Why does the filehandle break on the lambda call?

katzgrau commented 8 years ago

Was there a resolution, whether related to KLogger or not?

s0me0ther commented 8 years ago

Iits not related to klogger: I called Klogger in the destruct process of my app, where the filehandle of klogger is not any more available. my fail :)