Running a PHP script completely on server side

后端 未结 5 1811
眼角桃花
眼角桃花 2021-02-10 21:12

I\'m having a problem where putty gets regularly disconnected. So, when I run a PHP script from the terminal, it always gets interrupted. The script is supposed to run several h

相关标签:
5条回答
  • 2021-02-10 22:00

    Take a look at GNU Screen; it allows you to detach and reattach a session later, which is perfect for long-running scripts. Cron is a good option if you want it to happen in a recurring fashion; one-off batch jobs can be scheduled with something like at. For more intense computing needs, you might want to look into a more full-fledged job scheduling system like TORQUE.

    0 讨论(0)
  • 2021-02-10 22:03

    You need to prevent the process from terminating when the session disconnects.

    Something like this would work:

    nohup php myscript.php

    0 讨论(0)
  • 2021-02-10 22:03

    You can create a cron job to start the php script periodically based on a list of time tasks. More info. You could also start the task in the background from the console. i.e. php-cgi script.php& this would make the script a background task

    0 讨论(0)
  • 2021-02-10 22:05

    You can run your program in background

    php ./yourscript.php &
    
    0 讨论(0)
  • 2021-02-10 22:16

    You don't need to leave it run in a cron job - you can just run the php script inside a screen.

    Simply type;

    screen php /path/to/myphpscript.php
    

    A screen will continue running even after you disconnect from PuTTY. If you need to check up on it, you can use;

    screen -r
    

    To re-attach yourself to this process, and view any output.

    0 讨论(0)
提交回复
热议问题