linux php script timed execution

the first method:

1, writing shell scripts:

shell file: /home/www/shell/phpshell.php

  1. #!/bin/bash
  2. while [ true ]; do
  3. /bin/sleep 1
  4. /usr/bin/php /home/www/index.php >> /home/logs/phpshell.log
  5. done

2 and placed in the background:

/home/www/shell/phpshell.php &

3, use the tail -f command trace log.

The second method:


Use a PHP script execution in Crontab
  * * * * * / usr / bin / php /home/www/index.php execute php script every minute

b use the URL to execute scripts in Crontab

   If your PHP script can be triggered by a URL, you can use lynx or curl or wget to configure your Crontab. 
The following example uses the Lynx text browser to access the URL to execute PHP scripts per hour. Lynx text browser using the default URL to open a dialogue. But, like the following, we use the -dump option in lynx command line URL of the conversion output to standard output.

    Examples: * * * * * lynx -dump http://www.cnblogs.com/index.php

The following example uses CURL access URL to execute PHP script every 5 minutes. Curl is displayed by default in the standard output. Use "curl -o" option, you can also output the script to a temporary dump file.

    Examples: * / 5 * * * * / usr / bin / curl -o /home/logs/temp.log http://www.cnblogs.com/index.php

The following example is the use of WGET access URL to execute PHP script every 10 minutes. -q option means Quiet mode. "-O temp.txt" represents the output will be sent to a temporary file.

    Examples: * / 10 * * * * / usr / bin / wget -q -O /home/logs/temp.log http://www.cnblogs.com/index.php

The third method of execution per second shell script:

a shell script: /home/shell/phpshell.sh

   #!/bin/bash
   step = 2 # is the number of seconds, not more than 60
   for (( i = 0; i < 60; i=(i+step) )); do
   $(php '/home/fdipzone/php/crontab/tolog.php')
   sleep $step
   done
   exit 0
b crontab command script file
   * * * * * /home/shell/phpshell.sh

Guess you like

Origin www.cnblogs.com/jasonLiu2018/p/12146171.html