定期执行 PHP 脚本的最佳方法?

2022-01-03 00:00:00 cron php

如果我可以完全访问服务器,我可能会想出一种方法来做到这一点,但问题是它只是一个托管服务,除了FTP 访问外,我什么都没有.>

我想定期运行一个 PHP 脚本来检查过时/损坏的内容、聚合新内容、删除未使用的文件等,但是该脚本可能需要长达 60 秒来执行(由于内容的聚合),我觉得在处理更新一小时后访问该网站的第一个用户的请求时执行它就像一个笨蛋:P

24/7 离开我的家用电脑来安排请求不是一种选择.

解决方案

您可以使用在线 cron 服务来假装您拥有 cron 访问权限.

用你想执行的内容创建php文件

免费 Cron 在线网站

设置您的免费在线 cron 以每 x 分钟执行一次该文件.

I'd probably figure out a way to do this if I had full access to the server, however the problem is it's just a hosting service which leaves me with nothing but FTP access.

I would like to run a PHP script periodically to check for outdated/broken content, aggregate new content, delete files not in use etc, however the script can take up to 60 seconds to execute (due to aggregation of content) and I feel like an ass to just execute it while processing a request of the first user that visits the website an hour after it's been updated :P

Leaving my home PC on 24/7 to schedule requests is not an option.

解决方案

You can use an online cron service to essentially pretend like you have cron access.

Create php file with contents you would like executed

Free Cron Online Website

Set up your free online cron to execute that file every x minutes.

相关文章