PHP文件在指定时间放置内容
我有一个指向如下url的php文件:PHP文件在指定时间放置内容,php,Php,我有一个指向如下url的php文件: <?php header('Content-Type: text/plain'); echo file_get_contents($_GET['url']); 然而,弄清楚如何在每天的特定时间调用文件\u put\u内容,让我陷入了一个循环 问题:是否可以在本地php中每天的特定时间以上述方式编写文件?理想情况下,我想用今天的日期和“Data”后缀(即Mar-29-2018.txt)来命名文件 编辑 根据以下建议,我研究了cron:我认为我的用例的语
<?php
header('Content-Type: text/plain');
echo file_get_contents($_GET['url']);
然而,弄清楚如何在每天的特定时间调用文件\u put\u内容
,让我陷入了一个循环
问题:是否可以在本地php中每天的特定时间以上述方式编写文件?理想情况下,我想用今天的日期和“Data”后缀(即Mar-29-2018.txt)来命名文件
编辑
根据以下建议,我研究了cron
:我认为我的用例的语法是:
0 18 * * * path/to/my/command.sh
我认为日期语法是正确的,但我仍然不清楚如何将
cron
与我的php文件一起使用。既然我使用的是file\u put\u contents
,我是否应该将sh
文件扩展名改为php
?或者这是我的php文件中的cron
日期,我必须做一个.sh
(不管是什么?你可以检查时间戳和文件名
<?php
$todayHour = 18;
$todayMinute = 0;
$timeCreate = mktime($todayHour, $todayMinute, 0, date('m'), date('d'), date('Y'));
$todayFilename = 'data-' . date('Y-m-d') . '.txt';
if (time() >= $timeCreate && !file_exists($todayFilename)){
// Code input content file here
file_put_contents($todayFilename, $_GET['url']);
}
你正在寻找CRON或者如果你在Windows上:CRON可以运行任何文件,只要给它一个命令,你就可以在shell中使用它来执行,例如php file.php
让php执行一个名为file.php
@chris85的文件,澄清一下,php file.php
在php
和文件名之间有一个空格,对吗?这条评论有两行多行,所以我不能确定。如果我理解正确,就像第一项是代码语言。我所做的是在shell中输入:php path/to/my/file.php
我希望这是对的,我想我会在下午6:00发现……我想你误解了这个问题。OP希望脚本每天在特定的时间执行。@Mike谢谢先生,我错了
<?php
$todayHour = 18;
$todayMinute = 0;
$timeCreate = mktime($todayHour, $todayMinute, 0, date('m'), date('d'), date('Y'));
$todayFilename = 'data-' . date('Y-m-d') . '.txt';
if (time() >= $timeCreate && !file_exists($todayFilename)){
// Code input content file here
file_put_contents($todayFilename, $_GET['url']);
}