Bash 脚本来运行 php 脚本 [英] Bash script to run php script

查看:29
本文介绍了Bash 脚本来运行 php 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 php 脚本,我想使用 bash 脚本运行它,所以我可以使用 Cron 每分钟左右运行一次 php 脚本.

I have a php script that I want to be run using a bash script, so I can use Cron to run the php script every minute or so.

据我所知,我需要创建 bash 脚本来处理 php 脚本,然后我才能使用 Cron 工具/计时器.

As far as I'm aware I need to create the bash script to handle the php script which will then allow me to use the Cron tool/timer.

到目前为止,我被告知我需要:

So far I was told I need to put:

#!/pathtoscript/testphp.php

在我的 php 脚本的开头.我不知道从这里做什么...

at the start of my php script. Im not sure what to do from here...

有什么建议吗?谢谢.

推荐答案

如果你安装了 PHP 作为命令行工具(尝试将 php 发送到终端,看看它是否有效),你的shebang(#!) 行需要如下所示:

If you have PHP installed as a command line tool (try issuing php to the terminal and see if it works), your shebang (#!) line needs to look like this:

#!/usr/bin/php

将它放在脚本的顶部,使其可执行(chmod +x myscript.php),并创建一个 Cron 作业来执行该脚本(与执行 bash 脚本的方式相同)).

Put that at the top of your script, make it executable (chmod +x myscript.php), and make a Cron job to execute that script (same way you'd execute a bash script).

您也可以使用 php myscript.php.

这篇关于Bash 脚本来运行 php 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆