dongsheng66783619 2014-03-22 21:35
浏览 61
已采纳

从Windows命令行CMD解雇php脚本

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:

enter image description here

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongliao3450 2014-03-22 21:40
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器