pass crontab a variable and read it from PHP?

后端 未结 4 2060
无人共我
无人共我 2021-01-05 01:22

I have created a crontab rule:

* * * * * php /my/directory/file.php

I want to pass a variable to be used in the file.php from this crontab.

4条回答
  •  佛祖请我去吃肉
    2021-01-05 01:39

    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"
    

    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").

提交回复
热议问题