Bash script to run php script(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 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Bash 脚本来运行 php 脚本


基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01