gpt4 book ai didi

javascript - 基本的 cron 作业问题

转载 作者:行者123 更新时间:2023-11-28 07:17:55 24 4
gpt4 key购买 nike

我的 HTML 文件中有一个特定的脚本,我想使用 cron 作业每 24 小时运行一次。我的问题是我应该在托管商(主机)命令中输入什么路径。

我是否输入 php/path/to/index.php 因为这不会每 24 小时运行一次我的整个代码,我想知道如何每 24 小时运行一个特定的脚本。

附件是我的代码,提前谢谢您!!

<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<div id="header">
<h1>City Gallery</h1>
</div>

<div id="sidebar">

</div>

<div id="maincontent">
<h1>Rumours</h1>




<table id="myTable" width"100%">

<tr>
<th width="30%">From</th>
<th width="30%">Player</th>
<th width="40%">Price</th>
</tr>

<tr>
<td></br></td>
<td></br></td>
<td></br></td>
</tr>
</table>

<script>

// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");

// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(0);

// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);

// Add some text to the new cells:
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
cell3.innerHTML = "NEW CELL3";
</script>



</div>

<div id="rightbar">
</div>

<div id="footer">
</div>

</body>
</head>
</html>

最佳答案

在您的 cron 作业脚本中使用 cURL 或 wget,并使用 localhost 作为您获取的 URL 中的主机名。这样,您将通过运行 PHP 的 Web 服务器(通常是 Apache,但不一定)调用您的网页。

您必须设置一个特定的网页/URL 来完成您希望脚本每 24 小时完成的任务。

例如,您的 cron 脚本(位于 website-cron.sh 中)可能是:

#! /bin/sh

/usr/bin/curl --silent --show-error http://localhost/cron-script.php/parameters

您可以使用 crontab -e 将其放入 crontab 文件中,并输入此行以在每天凌晨 3:00 运行脚本:

0 3 * * *   /path/to/website-cron.sh

关于javascript - 基本的 cron 作业问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30646815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com