doubingqi5829 2017-04-13 06:17
浏览 321


I have a php script that use Mosquitto client. I am using putty SSH to access to the server. I want to run the php script in background continously even when I disconnect from putty. I have tried screen and nohup but it stop when closing putty window

Thank you

  • 写回答

2条回答 默认 最新

  • drqvsx1228 2017-04-13 06:49

    A simple solution is

    nohup php script.php &

    So you run script in background and disconnect the process from the terminal. If it doesn't help, try disown command after it. There is a good answer with detailed explanation of differences between these commands.

    To get full control of your script, a good choice would be a System V init script. There is a template at, which you can use.

    Copy template to /etc/init.d directory and rename it. In template you need to change variables:

    cmd="nohup php script.php"
    user="your user"

    Doing that you will be able to control your script by

    /etc/init.d/your_script start
    /etc/init.d/your_script stop

    Make sure you have permissions to write in /var/log/ and /var/run/, or run script as sudo(leave user="" empty)

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



  • ¥15 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办