当前位置:首页 > 操作系统 > Linux

thinkphp框架里用linux的crontab写php的定时脚本

本篇文章给大家分享的内容是thinkphp框架里用linux的crontab写php的定时脚本,有需要的朋友可以参考一下

在php内curl tp框架的路径就可以了,然后把这个php设crontab
例如:tp的访问地址是http://www.tp.com/index.php?m=admin&c=controller&a=action
写个php,例如tpcrontab.php

内容如下:

<?php
    $url = 'http://www.tp.com/index.php?m=admin&c=controller&a=action';
    $timeout = 60;
    $data = array();
    $header = array();
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查  
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);  // 从证书中检查SSL加密算法是否存在  
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);  
    curl_setopt($ch, CURLOPT_POST, true);  
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);   //CURLOPT_TIMEOUT 设置cURL允许执行的最长秒数
   
    $response = curl_exec($ch); 
   
    if($error=curl_error($ch)){  
        die($error);  
    }  
    curl_close($ch); 
    echo $response;

参考文章:https://bbs.csdn.net/topics/390805964

以上就是thinkphp框架里用linux的crontab写php的定时脚本的详细内容,更多请关注Gxl网其它相关文章!


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐