doutang7707 2019-08-06 10:26
浏览 102

如何:在一个PHP文件中运行多个Cron链接

My Domain Host only allows 2 CRON jobs to be set. I have one already set to download a file over FTP

I need to run 10 more Cron Links from a single PHP file. Is this at all possible?

Format of Cron Link (10 Parts): https://www.example.com?route=extension/module/import&import_id=1&part=1_10

Not sure how to test this out in a single PHP file

Would something like this work?

<?php
ini_set('display_errors', 1);
$response=curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=1_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=2_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=3_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=4_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=5_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=6_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=7_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=8_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=9_10");
curl_request("https://www.example.com/?route=extension/module/import&import_id=1&part=10_10");
function curl_request($url,$method="GET",$postFields="")
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if($method=="POST")
    {
        curl_setopt($ch, CURLOPT_POST, 1);       
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
    }
    else
    {
        curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    }
    $response = curl_exec($ch);
    echo "$response";
    return $response;
}
?>

Is it possible to add a time out between the links?

  • 写回答

2条回答 默认 最新

  • doutang7661 2019-08-06 10:40
    关注

    As I understand you want to run scripts periodically, but your web host only allows two cron jobs.

    One solution is that you can run a single Php script as a cron job. Within this script, you can check the current time. If the time is correct, then you can run the other scripts. For example run the main Php script every 10 min. This script can check if it is time to run the other Php scripts.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配