如何一遍又一遍地运行 .php 文件...也许是 cron?
我有一个 php 文件,它在 c++ exe 上调用 exec()。当 .exe 完成运行时,我需要再次运行 php 文件,重复 .
我想知道最好的方法是什么?该 .php 文件没有用户交互,需要完全自动化。
编辑:找到另一个解决方案,如果该进程已经在运行,则会终止该进程,这将很好地解决此问题。请参阅本页上的帖子。
I have a php file that calls exec() on a c++ exe.When the .exe is finishing running I need to run the php file again,repeat .
I am wondering what is the best way to do this? This .php file has no user interaction and needs to be completely automated.
EDIT:Found another solution that would kill the process if it is already running which will cover this issue well.See posts on this page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个简单的 Linux 行,它在后台启动脚本,并在脚本运行完成时使用
watch
命令重新启动脚本:一旦像这样启动了它,您就可以使用
ps
命令列出正在运行的进程并找到watch
的进程 ID,然后使用kill process_id
停止监视。运行这样的命令可能不是最佳实践,但它是一种快速且简单的解决方案,不需要系统上的任何特殊访问权限(而使用 cron 可能需要),并且不涉及编辑代码(而 codeigniter 解决方案将要)。
Here's a simple Linux line that starts up the script in the background and uses the
watch
command to restart the script whenever it finishes running:Once you've started it like this, you can use the
ps
command to list running processes and find the process ID forwatch
, and then usekill process_id
to stop watch.It's probably not best practice to run commands like this, but it's a quick and easy solution that doesn't require any special access privileges on the system (whereas using cron might), and doesn't involve editing your code (whereas a codeigniter solution will).
我以前没有使用过 codeigniter,但似乎有一个解决方案,如 wiki< /a>.
根据您访问系统的方式(无论您是否是管理员)以及您计划如何更新自动化命令,恕我直言,您可以使用这两种解决方案(Linux crontab 或 codeigniter cron 脚本)。
I haven't used codeigniter before but there seems to be a solution as described in the wiki.
Depending on how you can access the system (if you are admin or not) and depending on how you are planning to update the automated commands, IMHO, you could use both solution (Linux crontab or codeigniter cron script).