bash脚本运行PHP脚本 [英] Bash script to run php script
问题描述
我有,我想用一个bash脚本运行PHP脚本,这样我就可以用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
到终端看看它的工作原理),你的家当(#
)行需要看起来像这样:
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屋!