简体   繁体   English

作为cronjob运行时,facebook.php标头发送错误

[英]facebook.php headers sent error when run as cronjob

I have a file which includes facebook.php and it runs without any error if i run the URL directly. 我有一个包含facebook.php的文件,并且如果我直接运行URL,它将运行而没有任何错误。 But when i run it as cronjob i get the following error in email 但是当我将其作为cronjob运行时,我在电子邮件中收到以下错误

<br />
<b>Warning</b>:  session_start() [<a
href='function.session-start'>function.session-start</a>]: Cannot send session
cookie - headers already sent in
<b>/home/username/public_html/pathtofile/facebook.php</b> on line
<b>37</b><br />

And there is nothing being echoed before the inclusion of facebook.php since this file is being included at the top. 而且,在包含facebook.php之前,没有任何回应,因为此文件位于顶部。

require('facebook.php');
include_once("config.php");
include_once("functions.php");
 $app_id = 'my_app_id';
 $app_secret = 'my_app_secret';
 $facebook = new Facebook(array(
   'appId'  => $app_id,
   'secret' => $app_secret,
 ));

What could be the possible error? 可能是什么错误?

Maybe your session is already started 也许您的会话已经开始

if(!session_id()){
session_start();
}

same problem here. 这里同样的问题。 I wasn't able to pull much use from it, but I did find this (in case you haven't already seen it): issues with php command line 我无法从中获得很多用处,但是我确实找到了它(以防万一您还没有看到它): php命令行问题

I commented out the session_start() line in my facebook.php include file as a workaround ... seems to be working as best I can tell. 我将我的facebook.php包含文件中的session_start()行注释掉,这是一种解决方法...我似乎可以尽力而为。 Doesn't make much sense to me, but did either of you come up with a definitive reason and/or direction? 对我来说没有多大意义,但是你们两个都提出了明确的理由和/或方向吗? I'm a little surprised there isn't more discussion/google results about it.... 令我感到惊讶的是,没有关于它的更多讨论/ Google结果。

The issue is with php command line so its better to run at cron with wget instead of php-q 问题在于php命令行,因此最好在wron而不是php-q的cron上运行

i used wget http://exampl.com/url_for_script.php at cron url 我在cron url上使用了wget http://exampl.com/url_for_script.php

and its worked for me 它为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM