zoukankan      html  css  js  c++  java
  • linux使用crontab实现PHP执行定时任务及codeiginter参数传递相关

    http://www.phpddt.com/php/linux-crontab.html

    crontab:
    yum install crontabs //安装
    说明:
    /sbin/service crond start //启动服务
    /sbin/service crond stop //关闭服务
    /sbin/service crond restart //重启服务
    /sbin/service crond reload //重新载入配置
     
    查看crontab服务状态:service crond status
    手动启动crontab服务:service crond start
    查看crontab服务是否已设置为开机启动,执行命令:ntsysv //未实验成功
    加入开机自动启动: chkconfig –level 35 crond on  

    crontab任务命令:

    crontab [-u <用户名称>][配置文件] 或 crontab [-u <用户名称>][-elr]
    
    -e  编辑该用户的计时器设置。
    -l  列出该用户的计时器设置。
    -r  删除该用户的计时器设置。
    -u<用户名称>  指定要设定计时器的用户名称。

    contab格式

    Minute Hour Day Month DayOFWeek Command

    示例:

    1、建立要执行php文件

    #!/usr/local/php/bin/php -q 
    <?php
        echo  date('Y-m-d H:i:s')."from http://www.phpddt.com 
    ";
    ?>

    2、设置可以执行

    chmod +x test.php

    3、crontab -e 编写

    * * * * * /root/test.php >> test.log

    此步可以写上php路径,就不需要1、2步

    * * * * * /usr/bin/php -f /root/test.php >> test.log

    4、查看结果

    vim /root/test.log

    http://www.jb51.net/article/29136.htm

    Crontab中使用URL执行脚本:

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


    */5 * * * * /usr/bin/curl -o temp.txt http://www.jb51.net/myscript.php 

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

    */10 * * * * /usr/bin/wget -q -O temp.txt http://www.jb51.net/myscript.php 

     CodeIgniter 计划任务 Cron Schedule 0.1 

    http://blog.chinaunix.net/uid-26559452-id-3093545.html

    */5 * * * * php /var/www/ci210/index.php cron index

    注意codeigniter的路径和参数传递的方法。

  • 相关阅读:
    Linux YUM (Yellowdog Updater, Modified) Commands for Package Management
    awk命令例子详解
    sed命令例子详解
    浅谈XX系统跨平台迁移(测试环境)
    Postgres常用命令之增、删、改、查
    Postgres主备切换
    Postgres配置主从流复制
    Crontab定时任务
    GIL全局锁测试
    python try exception finally记录
  • 原文地址:https://www.cnblogs.com/mitang/p/4511394.html
Copyright © 2011-2022 走看看