Running PHP script completely server side

I have a problem when the putty is regularly turned off. Therefore, when I run the PHP script from the terminal, it is always interrupted. The script is supposed to run for several hours, so I had no luck with it.

How can I fully run this from the server side? I read about cron's work, but at this time I find it hard to understand. Is there an alternative to cron for what I need?

I have several PHP script files that need to be run one after the other, or maybe two at a time. Any ideas?

+4
source share
5 answers

You do not need to leave it running in the cron job - you can just run the php script inside the screen.

Just enter

screen php /path/to/myphpscript.php 

The screen will continue to work even after disconnecting from PuTTY. If you need to check it, you can use;

 screen -r 

To reconnect to this process and view any output.

+9
source

You need to prevent the process from ending when the session is disconnected.

Something like this will work:

nohup php myscript.php

+3
source

You can create a cron job to run a php script periodically based on a list of time jobs. Additional information . You can also run the task in the background from the console. those. php-cgi script.php& this would make the script a background task

+1
source

Take a look at the GNU screen ; it allows you to disconnect and reconnect the session later, which is ideal for long scenarios. Cron is a good option if you want this to happen in a repeating way; one-time batch jobs can be scheduled with at . For more intensive computing needs, you may need a more fully functional task scheduling system, such as TORQUE .

+1
source

You can run your program in the background.

 php ./yourscript.php & 
0
source

All Articles