What options are there for executing a PHP script at a certain time every day?(每天在特定时间执行 PHP 脚本有哪些选项?)
问题描述
我有一个 PHP 脚本,需要在每个工作日的特定时间运行.cron
或 Windows 任务调度程序是执行此操作的唯一方法吗?
有没有办法从另一个 PHP 脚本中进行设置?
I have a PHP script that needs to be run at certain times every weekday. Is cron
or Windows task scheduler the only way to do this?
Is there a way to set this up from within another PHP script?
推荐答案
取决于时间的精确程度.我见过使用的一种技术(称为穷人的 cron")是让经常访问的脚本(例如网站的主页)在一段时间后在第一页加载时触发任务(在数据库).
Depends how exact the timing needs to be. A technique I've seen used (dubbed "poor man's cron") is to have a frequently accessed script (a site's home page, for example) fire off a task on the first page load after a certain time (kept track of in the database).
不过,如果您需要任何形式的保证准确性,cron 或 Windows 计划任务确实是最佳选择.如果您的主机不支持它们,则是时候换一个更好的了.
If you need any sort of guaranteed accuracy, though, cron or a Windows scheduled task is really the best option. If your host doesn't support them, it's time to get a better one.
这篇关于每天在特定时间执行 PHP 脚本有哪些选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:每天在特定时间执行 PHP 脚本有哪些选项?


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01