dt4233 2013-09-09 05:50
浏览 16
已采纳

运行PHP脚本

I need keep running the PHP script but I have a problem, currently I use putty to login to the server then execute PHP code. When I close putty session the script stops the execution.

Steps:

  1. login to server with putty
  2. running PHP script eg) PHP filename

but when I close the putty session the program will obvious close. I need to keep running the program on server regardless of closing putty and anyone logging into server can stop it and run it again as a process. How to run a php script independent of putty session, which can be controlled by anyone logging to server?

  • 写回答

2条回答 默认 最新

  • duanpi7107 2013-09-09 06:17
    关注

    I'm not sure your question is really in the scope of programming, it is more a unix/linux specific question of "How to run a program from shell that doesn't close when I close the terminal". PHP happens to be that program.

    You can do php -f scriptname.php > /dev/null 2>/dev/null & disown.

    STDOUT and STDERR will be redirected to /dev/null (or you can change those to real files) and the ambersand will fork the process. Disown will remove the running PID from the terminal session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本