我试图使用PHP命令行(从cron选项卡)。我知道如何像这样添加参数:
cd /home/users/public_html/; php -f script.php some_value
我想(或需要)动态添加当前日期:
cd /home/users/public_html/; php -f script.php current_date
使用wget我这样做:
wget "https://mysitecom/script.php?currentdate=`date +'%s.'%N`"
但是我找不到任何方法来做类似的php命令行。
我试过:
cd /home/users/public_html/; php -f script.php `date+'%s.'%N`
我得到错误"Command not found"。
我也尝试了在一个答案中提出的解决方案:
cd /home/users/public_html/; php -f script.php date+'%s.'%N
我得到字符串"date+'%s.'%N"
与另一个提出的解决方案:
cd /home/users/public_html/; php -f script.php "$(date +"%s.%N")"
我在cron发送的电子邮件中得到这些错误:
/usr/local/cpanel/bin/jailshell: -c: line 0: unexpected EOF while looking for matching `"'
/usr/local/cpanel/bin/jailshell: -c: line 1: syntax error: unexpected end of file
当从命令行(CLI)使用PHP时,它们不称为GET变量,而称为参数
有两个参数传递给每个脚本从命令行运行称为$argv和$argc
要记住的一件事是,第一个argv[0]
出现包含正在运行的脚本的名称。除此之外,$argv[]
中的参数按照它们在命令行
argc是传递给脚本
的变量个数。arcv是传递给
的所有变量的数组。如果它有帮助的话,它们就像"C"的等价物如果你曾经写过任何"C"代码
附加信息
用今天的日期调用你的脚本,像这样使用
cd /home/users/public_html/; php -f script.php "$(date +"%s.%N")"
根据需要调整格式
虽然如果你想今天的日期在脚本中,我不知道为什么你不会得到从PHP脚本本身。
我终于让它工作了。语法错误:
:
cd /home/users/public_html/; php -f script.php `date+'%s.'%N`
需要:
cd /home/users/public_html/; php -f script.php `date +'%s.'%N`