pass crontab a variable and read it from PHP?

后端 未结 4 2055
无人共我
无人共我 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:51

    When you execute a PHP script from command line, you can access the variable count from $argc and the actual values in the array $argv. A simple example.

    Consider test.php

    Executing this using php test.php a b c:

    4 arguments given:
    Array
    (
        [0] => test.php
        [1] => a
        [2] => b
        [3] => c
    )
    

提交回复
热议问题