简体   繁体   English

Codeigniter-创建手动调度程序

[英]Codeigniter - creation of a manual scheduler

I want to create a scheduler in Codeigniter as in, at 21:24 "this" record should be updated. 我想在Codeigniter中创建一个调度程序,就像在21:24处,“此”记录应该被更新。

I have searched a lot but the ultimate answer was to create a cron job. 我进行了很多搜索,但最终的答案是创建一份工作。

Can I dynamically create cron job in Codeigniter? 我可以在Codeigniter中动态创建cron作业吗?

Actually I was thinking to create a class in which a method will keep checking: 实际上,我在考虑创建一个类,其中的方法将不断检查:

  1. Time. 时间。
  2. Anything to update. 任何更新。

How to create such a function most efficiently, as a request may come from n amount of users at random times to do a specific job at different time? 怎样才能最有效地创建这样的功能,因为随机时间可能有n个用户发出请求,要求在不同时间执行特定工作?

I would not dynamically create cron jobs. 我不会动态创建cron作业。

Instead I would have one script that is called through cron once a minute (once every 10 minutes...) and store all the jobs in a database with the time they are supposed to run. 取而代之的是,我有一个脚本,该脚本每分钟(每10分钟一次)通过cron调用一次,并将所有作业与应该运行的时间一起存储在数据库中。

Then in your script you can check the database and see if there are any jobs that need to run at this time exactly or between the time of the last check and now. 然后,您可以在脚本中检查数据库,以查看此时是否正好或者在上次检查到现在之间需要运行任何作业。

To create a CRON job from PHP use the exec command. 要从PHP创建CRON作业,请使用exec命令。 This should work (untested, on mobile) 这应该有效(未经测试,在移动设备上)

exec(crontab -l | { cat; echo "0 0 0 0 0 php your_php_script.php"; } | crontab -);

Alternatively if you want to schedule a single job better to us the 'at' command. 或者,如果您想更好地为我们安排一项工作,请使用“ at”命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM