Why am i getting Undefined index: HTTP_HOST error?

后端 未结 2 868
遥遥无期
遥遥无期 2021-01-22 18:05

I am using Facebook SDK to post some test wall post on my own facebook page. It works fine when i run the script on my browser but when i run it from terminal it gives me as err

相关标签:
2条回答
  • 2021-01-22 18:10

    If you run your script from a terminal, or a cron job, there is no HTTP environment.

    A possible solution to this is to run the script with a wget http://.../parameters instead of with php scriptname.

    0 讨论(0)
  • 2021-01-22 18:16

    The cron executes the PHP not like a module of apache, so many environment variables are not set by the server. When executing from cron your PHP script is like GCI one, more precisely its CLI (command line interface - php-cli). So as you can imagine, there is no web server and there is no HTTP_HOST.

    PS: You can transfer data (urls, hostname or whatever you like) as command line arguments (environment variables) to PHP: Command line usage

    Addition:

    $php -f cronjob.php HTTP_HOST=www.mysite.com #example
    
    
    <?php
        // cronjob.php
        $host = $_GET['HTTP_HOST']; // Get the host via GET params
    ?>
    
    0 讨论(0)
提交回复
热议问题