Reputation:
I have to find the url from where the cron job calls an API.
I tried <?=$_SERVER['HTTP_HOST'];?>
in the cron file but it returned empty and also <? phpinfo() ?>
did not help.
Cron command: * * * * * php -q /home/karenib/public_html/scr/cron.php
Upvotes: 0
Views: 1523
Reputation: 2639
The <?=$_SERVER['HTTP_HOST'];?>
will will not be populated when running it from a cronjob like php -q /home/karenib/public_html/scr/cron.php
, since the file is not accessed via HTTP.
You can pass the host through params like
php -q /home/karenib/public_html/scr/cron.php -h=http://example.com
And access it like
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : getopt('h:');
However, if you still need the HTTP_HOST
populated, you can use curl like
curl http://example.com/path/to/cron.php &> /dev/null
Upvotes: 2