Search code examples
phpvariablescronargv

Cron Job Pass and Retrieve variables with php


I am running the following cron job:

wget -q --spider --timeout=5 --tries=1 "http://www.publicvent.org/wow/kiwi/script.php" index=1

In script.php I have:

require_once('functions-admin.php');
$argv = $_SERVER['argv'];
$index = $argv[1];
mail('email', 'Test', $index, '');

I have also tried unsuccessfully to use:

require_once('functions-admin.php');
parse_str(argv[n]);
mail('email', 'Test', $index, '');

to no success.

The cron job runs fine, but there is no value in $index.

Any help is appreciated. Thanks.


Solution

  • You can do it using $_GET

    wget -q --spider --timeout=5 --tries=1 "http://www.publicvent.org/wow/kiwi/script.php?index=1"
    

    And in your script:

    require_once('functions-admin.php');
    $index = $_GET['index'];
    mail('email@localhost', 'Test', $index, '');
    

    Regards!