I feel like I'm missing something here. php is set up in my system variable PATH. I'm trying to execute a php script from the Window command line, here is my script:
<?php
$file = "test_log.txt";
$content = date("Y-m-d H:i:s") . " - Action logged.
";
file_put_contents($file, $content, FILE_APPEND);
echo "That worked. I think.";
?>
When called from my browser it works perfectly. A log file is appended with the latest action. However when called from the command line I get the echo, but nothing else happens, no appendment of the log file. See below:
Any ideas?
This should do it:
file_put_contents(__DIR__.'/'.$file, $content, FILE_APPEND);
Reason: Your webserver has a different $_SERVER['DOCUMENT_ROOT'] (and current work directory) than the Command Line Interpreter.