douyujun0152 2012-10-10 11:21
浏览 2117
已采纳

为什么我得到Undefined index:HTTP_HOST错误?

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 error as below, i don't know what's wrong please help. I want to post on my facebook page using php CRON scripts like every 6 hours.

Undefined index: HTTP_HOST error in Facebook/src/base_facebook.php

  • 写回答

2条回答 默认 最新

  • dongtao9158 2012-10-10 11:24
    关注

    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 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
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗