Use Linux crontab to write PHP timing scripts in the thinkphp framework

不言
Release: 2023-03-23 12:34:02
Original
3159 people have browsed it

The content of this article is to use Linux crontab to write PHP timing scripts in the thinkphp framework. Friends in need can refer to

Just find the path of the curl tp framework in PHP. Then set this php to crontab
For example: the access address of tp is http://www.tp.com/index.php?m=admin&c=controller&a=action
Write a php, for example tpcrontab.php

The content is as follows:

<?php
    $url = &#39;http://www.tp.com/index.php?m=admin&c=controller&a=action&#39;;
    $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;
Copy after login

Reference article: https://bbs.csdn.net/topics/390805964

                                                                                                                               net/qq_35979073/article/details/79352450



The above is the detailed content of Use Linux crontab to write PHP timing scripts in the thinkphp framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template