문제

I am trying to run a CLI php script, while most of it works, I am not able to dump the log file.

Code:

    private function WriteLogForCLI($msg){
        try{
            $ttw = " *************************************************** " . PHP_EOL;
            $ttw .= " *" . PHP_EOL;
            $ttw .= " * TIME STAMP: " . date("m/d/Y H:i:s");
            $ttw .= " *" . PHP_EOL;
            $ttw .= " * $msg" . PHP_EOL;
            $ttw .= " *" . PHP_EOL;
            $ttw .= " *************************************************** " . PHP_EOL;
            $logfile = str_replace('//', '/', FCPATH . 'assets/logs/' . date("m-d-Y") . '.txt');                
            $fh = fopen($logile, 'wb');                 
            //var_dump($fh);
            //var_dump($ttw);               
            fwrite($fh, $ttw); 
            fclose($fh);                
            //var_dump($logfile);
        }catch(Exception $e){
            var_dump($e->getMessage());
        }
    }

$logfile path is correct, and is the absolute location of where this file should be located... for instance /var/www/the_site/assets/logs/03-06-2014.txt is var_dump'd which is correct.

I have made sure the directory this is written to has 0777 access.

What can I do to make this work? All I am trying to do is write a log file that has a $msg, but have it run from cli.

I've tried it with my normal login, and the root login and the file never gets written.

Server is Ubuntu 13.10 server, with PHP 5.5.3

도움이 되었습니까?

해결책

you have

$logfile = str_replace('//', '/', FCPATH . 'assets/logs/' . date("m-d-Y") . '.txt');

but, you are using $logile in fopen function

$fh = fopen($logile, 'wb');   

so, change to

$fh = fopen($logfile, 'wb');   
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top