Why am i getting Undefined index: HTTP_HOST error?

后端 未结 2 870
遥遥无期
遥遥无期 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: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
    
    
    
    

提交回复
热议问题