为什么我得到未定义的索引:HTTP_HOST错误? [英] Why am i getting Undefined index: HTTP_HOST error?

查看:1731
本文介绍了为什么我得到未定义的索引:HTTP_HOST错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Facebook SDK在我自己的Facebook页面上发布一些测试墙帖子。它工作正常,当我在我的浏览器上运行脚本,但当我从终端运行它给我的错误,如下所示,我不知道有什么问题请帮助。

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.

未定义的索引:Facebook / src / base_facebook.php中的HTTP_HOST错误

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

推荐答案

cron执行PHP不像apache的模块,所以许多环境变量不是由服务器设置的。当从cron执行时,你的PHP脚本就像GCI,更确切地说是它的CLI(命令行界面 - php-cli)。所以你可以想象,没有web服务器,没有HTTP_HOST。

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:你可以传输数据(urls,主机名或任何你喜欢) PHP的参数:命令行用法

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

添加:

$php -f cronjob.php HTTP_HOST=www.mysite.com #example


<?php
    // cronjob.php
    $host = $_GET['HTTP_HOST']; // Get the host via GET params
?>

这篇关于为什么我得到未定义的索引:HTTP_HOST错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆