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

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

问题描述

我正在使用Facebook SDK在我自己的Facebook页面上发布一些测试墙贴。当我在浏览器上运行脚本时,它的工作正常,但是当我从终端运行它时,它给我的错误如下,我不知道有什么问题请帮忙。我想使用php CRON脚本发布在我的Facebook页面上,每6小时一次。

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,hostname或任何你喜欢的)作为命令行传输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天全站免登陆