第一种方法:

1、编写shell脚本:

shell文件:/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、并且放入后台运行:

/home/www/shell/phpshell.php &

3、使用tail -f 命令跟踪日志。

第二种方法:


a 在Crontab中使用PHP执行脚本
  * * * * * /usr/bin/php /home/www/index.php  每分钟执行php脚本

b 在Crontab中使用URL执行脚本

如果你的PHP脚本可以通过URL触发,你可以使用lynx或curl或wget来配置你的Crontab。
下面的例子是使用Lynx文本浏览器访问URL来每小时执行PHP脚本。Lynx文本浏览器默认使用对话方式打开URL。但是,像下面的,我们在lynx命令行中使用-dump选项来把URL的输出转换来标准输出.

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

下面的例子是使用CURL访问URL来每5分执行PHP脚本。Curl默认在标准输出显示输出。使用”curl -o”选项,你也可以把脚本的输出转储到临时文件。

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

下面的例子是使用WGET访问URL来每10分执行PHP脚本。-q选项表示安静模式。”-O temp.txt”表示输出会发送到临时文件。

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

第三种每秒执行shell脚本方法:

a shell脚本:/home/shell/phpshell.sh

   #!/bin/bash
   step=2 #间隔的秒数,不能大于60
   for (( i = 0; i < 60; i=(i+step) )); do
   $(php '/home/fdipzone/php/crontab/tolog.php')
   sleep $step
   done
   exit 0
b crontab 命令执行脚本文件
   * * * * * /home/shell/phpshell.sh
 

linux 定时执行php脚本的更多相关文章

  1. Linux定时执行.sh脚本

    因为测试ffmpeg推流用flv方式的话没有做自动断流,所以要先用.sh脚本来执行关流,降低CPU和其他资源占用 首先编写.sh文件 #! /bin/bash echo "kill ffmp ...

  2. 【转】linux 定时执行shell脚本

    在oracle 中可以利用dbms_job包定时执行pl/sql.sql过程,在像备份等需要在操作系统级定时任务只能采用crontab来完成 本文讲述crontab具体用法,以供备忘. 在oracle ...

  3. linux 定时执行shell脚本

    转自:http://blog.csdn.net/jingxiangren/article/details/4745631 在oracle 中可以利用dbms_job包定时执行pl/sql.sql过程, ...

  4. linux定时执行shell脚本

    写一个shell脚本,定时执行简单示例 很多时候我们有希望服务器定时去运行一个脚本来触发一个操作,比如说定时去备份服务器数据.数据库数据等 不适合人工经常做的一些操作这里简单说下 Shell俗称壳,类 ...

  5. linux定时执行php脚本

    1.查看lynx命令所在的路径 whereis lynx 或者 which lynx 如果没有,则安装 yum install lynx 或者 apt-get方式(ubuntu) 2.建立 shell ...

  6. Linux 定时执行shell脚本命令之crontab

    crontab可以在指定的时间执行一个shell脚本以及执行一系列Linux命令 例如:服务器管理员定时备份数据库数据.日志等 详解: 常用命令: crontab –e //修改 crontab 文件 ...

  7. 使用crontab,让linux定时执行shell脚本

    阅读目录 1. cron服务[Ubuntu环境] 2. crontab用法 3. 编辑crontab文件 4. 流程举例 5. 几个例子 Linux中,周期执行的任务一般由cron这个守护进程来处理. ...

  8. 【Linux】使用crontab,让linux定时执行shell脚本

    阅读目录 1. cron服务[Ubuntu环境] 2. crontab用法 3. vim编辑crontab文件 4.Cron各项描述 5.例子解释 Linux中,周期执行的任务一般由cron这个守护进 ...

  9. linux定时执行python脚本

    每天清晨 4:00:01,用python执行/opt/aa.py文件. 编辑定时任务: #crontab -e 加入: 0 4 * * * python /opt/aa.py 保存,退出即可. 如果执 ...

随机推荐

  1. install cpanm

    wget http://cpanmin.us mv index.html cpanm chmod +x cpanm

  2. STL set使用例子

    #include<iostream>#include<set>using namespace std; #include<stdlib.h> #define ran ...

  3. Jmeter plugin jp@gc - PerfMon Metrics Collector

    Jmeter由于是开源工具,所以目前有很多插件可以供使用,最简单的方法是先把Plugin Manager安装了 下载地址:https://jmeter-plugins.org/wiki/Plugins ...

  4. shell 判断文件是否存在

    举例 #!/bin/sh myFile="/var /log/httpd/access.log" if [ ! -e "$myFile" ]; then tou ...

  5. Linux下安装JDK并配置环境变量

    1. 查询是否默认安装有JDK [root@localhost bin]# java -version java version "1.6.0_22" OpenJDK Runtim ...

  6. scrollbar_test

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. prototype数组方法的实现

    数组插入元素push Array.prototype.push=function(){ for(var i=0;i<arguments.length;i++){ this[this.length ...

  8. python学习:环境搭建

    1.图解eclipse环境下安装python3.x插件支持:http://www.tuicool.com/articles/M3Afyu 其中如果 然后,选择Add按钮,Name:Python3,Lo ...

  9. Delphi日期函数、日期加减

    Delphi里有现成的函数可以实现日期加减,是在DateUtils单元里的. function IncYear(const AValue: TDateTime; const ANumberOfYear ...

  10. tomcat gzip compression not working for large js files

    solution 1: <Connector port="8080" protocol="HTTP/1.1" connectionTimeout=&quo ...