问题描述
我创建了一个 crontab 规则:
I have created a crontab rule:
* * * * * php/my/directory/file.php
我想从这个 crontab 传递一个要在 file.php 中使用的变量.
I want to pass a variable to be used in the file.php from this crontab.
这样做的最佳方法是什么?
What is the best method to do this?
推荐答案
请记住,在 shell 中运行 PHP 与在 Web 服务器环境中运行完全不同.如果你之前没有做过命令行编程,你可能会遇到一些惊喜.
Bear in mind that running PHP from the shell is completely different from running it in a web server environment. If you haven't done command-line programming before, you may run into some surprises.
也就是说,将信息传递到命令中的常用方法是将其放在命令行中.如果你这样做:
That said, the usual way to pass information into a command is by putting it on the command line. If you do this:
php /my/directory/file.php "some value" "some other value"
然后在你的脚本中,$argv[1] 将被设置为 "some value" 而 $argv[2] 将被设置为设置为 其他值".($argv[0] 将被设置为 "/my/directory/file.php").
Then inside your script, $argv[1] will be set to "some value" and $argv[2] will be set to "some other value". ($argv[0] will be set to "/my/directory/file.php").
这篇关于通过 crontab 一个变量并从 PHP 读取它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)