简体   繁体   English

从脚本启动计划的任务

[英]Launch scheduled task from script

On a Windows server, we have a task which runs occasionally, using "Scheduled Tasks" to control it. 在Windows服务器上,我们有一个偶尔运行的任务,使用“计划任务”对其进行控制。 (best not to run it directly, since it might need to be run as a particular user, and the Scheduled Task configuration has all the appropriate passwords). (最好不要直接运行它,因为它可能需要以特定用户的身份运行,并且“计划任务”配置具有所有适当的密码)。

We'd like to control this via a PHP script, so that visitors to a website can request the task be run. 我们希望通过PHP脚本进行控制,以便网站访问者可以请求运行该任务。 Can PHP trigger the scheduled task? PHP可以触发预定任务吗? Including giving an error or taking no action if the task is already running. 包括给出错误或如果任务已在运行则不采取任何措施。

Note: lockfiles etc. probably not a useful solution, since the task could fail/crash before completing 注意:lockfiles等可能不是一个有用的解决方案,因为任务可能在完成之前失败/崩溃

An easy way : let your task run all the time but do nothing till it finds some specific file, then delete it and do its job (then go back to wait). 一种简单的方法:让您的任务一直运行,但是什么也没做,直到找到特定的文件,然后将其删除并执行其工作(然后返回以等待)。

You PHP (or whatever) script just have to create that file ... 您的PHP(或其他任何脚本)脚本只需创建该文件即可。

If you have control of PHP environment, then you can directly execute external application within PHP using shell_exec and with additional parameters. 如果可以控制PHP环境,则可以使用shell_exec和其他参数直接在PHP中执行外部应用程序。 Also you can use mutex like checks in the related task to prevent multiple executions. 您也可以在相关任务中使用互斥体(如检查)来防止多次执行。

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

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