是否有任何与平台无关的方法来使用 PHP 安排任务?
我目前正在寻找一种方法,可以构建一个调度系统,该系统可以在特定日期和/或时间运行脚本,并且以一种不关心它所在的操作系统的方式执行此操作。我知道在 linux/unix 上,我可以使用 cron 添加输入,但是在其他操作系统上呢?没那么多。
另外,如果有一种方法可以让它在不依赖外部软件(例如 cron)的情况下执行,我也有兴趣了解这些选项,尽管我意识到这对于 PHP 来说可能有点困难。
感谢您在此事上的帮助!
I'm currently looking for a way that I can build a scheduling system that could run scripts at a certain date and/or time, and do it in such a way that it doesn't care what operating system it's living on. I know with linux/unix, I can add enteries using cron, but with other OS's? NOt so much.
Also if there's a way to have it execute without relying on external software such as cron, I'd be interested to learn about those options as well, although I realize that's probably a stretch with PHP.
Thanks for your help in this matter!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你用 PHP 编写一个每天 24 小时运行的持久服务器,那么调度任务就很容易了;永远循环并每秒检查当前时间是否有任何计划的任务并运行它们...运行代码或使用
exec
生成一个进程来执行此操作。假设您不打算用 PHP 编写持久服务器,那么不,没有与平台无关的方法来使用操作系统来安排任务。
If you write a persistent server in PHP that runs 24 hours a day, then scheduling tasks is easy; loop forever and check if there are any tasks scheduled for the current time each second and run them... run the code or spawn a process to do so with
exec
.Assuming you did not intend to write a persistent server in PHP, then no, there's no platform agnostic way to schedule tasks with the operating system.