通过 crontab 一个变量并从 PHP 读取它? [英] pass crontab a variable and read it from PHP?

查看:28
本文介绍了通过 crontab 一个变量并从 PHP 读取它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 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 读取它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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