yingjiusheng PHP Dev Engineer

CentOs定时任务创建

2017-07-12

linux下如和执行定时脚本文件,以及各参数的含义。

启动服务

/etc/init.d/crond start

crontab命令格式

  • crontab -l 显示当前的crontab 文件(默认编写的crontab文件会保存在 (/var/spool/cron/用户名 例如: /var/spool/cron/roger)
  • crontab -r 删除当前的crontab (谨慎使用此方法,因为将会把所有的计划任务全部删除)
  • crontab -e 使用编辑器编辑当前的crontab文件

crontab文件格式

    minutes hour day-of-month month-of-year day-of-week commands

    minute - 从0到59的整数 
    hour - 从0到23的整数 
    day - 从1到31的整数 (必须是指定月份的有效日期)
    month - 从1到12的整数 (或如Jan或Feb简写的月份)
    dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
    command - 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令)

案例

    crontab -e //编辑执行脚本任务内容
    //vim填写以下内容 
    */1 * * * * curl http://hr-test.local.com/Script/spiderQcwy/demo.html>>/tmp/test.txt
    //每隔一分钟执行一次
    crontab -l //查看执行任务

linux 添加域名解析

 vim /ect/hosts
 //添加解析域名   127.0.0.1 www.local.com

curl 执行网址命令

 curl http://www.baiduy.com

php 不间断脚本运行

ignore_user_abort(true);//如果设置为 true,则忽略与用户的断开,如果设置为 false,会导致脚本停止运行。如果未设置该参数,会返回当前的设置。
set_time_limit(0);

php执行影响超时配置

  • php.ini
max_execution_time//设置此值来控制最大执行时间
//一般从代码中set_time_limit(0)便可解决
  • nginx
request_terminate_timeout //此参数为nginx最大响应的时间
//修改为0s 则nginx不会有超时限制

Similar Posts

Content