PHP - 远程文件更改时的电子邮件通知

2023-10-10php开发问题
1

本文介绍了PHP - 远程文件更改时的电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想知道是否有办法让我的 Web 服务器上的 php 脚本在来自另一个 Web 服务器的文件发生更改时向我发送电子邮件.

I was wondering if there's a way to have a php script on my web server email me whenever a file from another web server changes.

例如,有一个经常变化的文件:http://media1.clubpenguin.com/play/en/web_service/game_configs/paper_items.json

For instance, there's this file that changes frequently: http://media1.clubpenguin.com/play/en/web_service/game_configs/paper_items.json

我写了一篇关于游戏的博客,该文件对于在我的竞争对手之前创建更新帖子非常重要.但我经常忘记检查它.

I blog about a game and that file is very important for creating post on updates before my competitors. I often forget to check it though.

有没有办法让脚本在文件更新时通过电子邮件发送给我,或者检查该文件以查看它是否已更新,如果有则通过电子邮件发送给我?

Is there a way to have a script email me whenever that file updates, or check that file to see if it has updated, and email me if it has?

推荐答案

您需要将这两个文件放在同一个文件夹中.

You need have this two files in same folder.

  • old.json
  • scriptForCron.php

scriptForCron.php 中写:

$url='http://media1.clubpenguin.com/play/en/web_service/game_configs/paper_items.json';
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$execute = curl_exec($ch);

$fp=fopen('old.json','w+');
$oldjson=fread($fp,filesize('old.json'));

if($execute!=$oldjson){
 mail('your@mail.com','Yoohoo', 'File changed');
 fputs($fp,$execute);
}
fclose($fp);

然后将 scriptForCron.php 添加到 cron 作业.您可以要求托管支持.

And then add scriptForCron.php to cron job. You can ask hosting support for it.

这篇关于PHP - 远程文件更改时的电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17