How to run a php url with parameters in cron tab

12,467

Solution 1

Ideally running PHP in command line interface (CLI) you would use $argv and $argc globals to pass parameters to the script.

Example: my_php_script.php

 <?
    var_dump($argv);


    php my_php_script.php arg1 arg2


array(3) {
  [0]=>
  string(17) "my_php_script.php"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
}

Hari

Solution 2

Show us your crontab (or at least the row with the PHP script). If you perform it like:

php script.php?param1=123

The above will not work. Instead do it like this:

wget http://localhost/script.php?param1=123&param2=345 -o /dev/null

Then it should work. If not, give more details.

Keep in mind, that the suggestion is JUST AN EXAMPLE. This would imply you have a running web server, that is configured to run PHP files, etc.

Share:
12,467
user1259132
Author by

user1259132

Updated on June 23, 2022

Comments

  • user1259132
    user1259132 almost 2 years

    Possible Duplicate:
    How to run a php script in cron

    I have a php script that is set to run in cron.I want to run the url with passing one parameter. I tried to pass parameters as query string and put in crontab it didn't work. How to run a url with parameters using cron?

    php /var/www/prod/Reports/[email protected]

  • user1259132
    user1259132 over 11 years
    Yes , i tried php script.php?param1=123, it is not working
  • user1259132
    user1259132 over 11 years
    Yes Veseliq, The script works perfect without parameters :)
  • ddinchev
    ddinchev over 11 years
    Did you read my answer at all?
  • user1259132
    user1259132 over 11 years
    I was telling everything configured well ( a running web server, that is configured to run PHP files, etc. )
  • Gaia
    Gaia over 11 years
    wget is the simplest way to get the job done.