Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Cron作业+;啁啾_Php_Unix_Cron_Twitter - Fatal编程技术网

Php Cron作业+;啁啾

Php Cron作业+;啁啾,php,unix,cron,twitter,Php,Unix,Cron,Twitter,从12:30开始(一直到1:30、2:30等),我的应用程序每小时都会发布一条静态推文。我目前正在使用Matthharris的twitter API。我也有一份cron的工作 30 * * * * php -q /home1/USER_NAME/public_html/twitter/index.php 我遇到的问题是,当我手动刷新index.PHP时,PHP代码可以工作&我的cron作业可以工作。我从cron工作中收到的电子邮件是: Error 200 我想知道的是,如何让我的cron

从12:30开始(一直到1:30、2:30等),我的应用程序每小时都会发布一条静态推文。我目前正在使用Matthharris的twitter API。我也有一份cron的工作

30 * * * *   php -q /home1/USER_NAME/public_html/twitter/index.php
我遇到的问题是,当我手动刷新index.PHP时,PHP代码可以工作&我的cron作业可以工作。我从cron工作中收到的电子邮件是:

Error 200
我想知道的是,如何让我的cron工作?我的cron作业中没有任何错误

include 'tmhOAuth/tmhOAuth.php';

$tmhOAuth = new tmhOAuth(array(
    'consumer_key' => 'XXX',
    'consumer_secret' => 'XXX',
    'user_token' => 'XXX',
    'user_secret' => 'XXX',
));

// Bahrain's time zone
date_default_timezone_set ('Asia/Riyadh');

// Set status message
$timezone= date("g:i");
$tweetMessage = "It's now" .$timezone. "in Bahrain";

//Response
$response = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array('status' => $tweetMessage));

//Do something if the request was unsuccessful    
if ($response != 200) {
    echo 'Error 200';
}
尝试:

这是正确的语法,但是在您的代码中,您实际上期望从页面得到响应,如果使用cron,这将不起作用


您可以像下面所说的那样,使用wget获取实际的URL,或者使用Curl实际发布和请求该URL。如果使用Curl,您将能够使用标准cron,因为Curl实际上会收到响应。

错误发生后,
$tmhOAuth->response
的内容是什么?看看JustHost,他们设置cron作业的方式与此类似:uuuu124; u124 124; u124 124; u124; u124| u124| u124; u124| u124;|u124;命令:-这5个框表示分钟、小时、每天、每月、每年(这是下拉菜单)命令行只是我的脚本所在的位置,在本例中是“www.domainname.com/twitter/index.php”,我想很多主持人都是这样的,这让我很烦。我不喜欢这种方法,因为它会将cron作业放在一个可公开访问的页面上,在这个页面上,碰巧请求该页面的任何人都在运行该脚本。如果是这种情况,有时我会向脚本传递一个参数,如www.domainname.com/twitter/index.php?arg1=121。通过这种方式,在脚本中,您可以验证某人是否只是点击了该页面…/twitter/index.php并运行cron。我认为总的来说,更好的做法是让你的作业不是在你的Web服务器上提供的页面,而是放在另一个文件夹中。我已经解决了这个问题,一切都很好,只是我的命令没有。我使用的命令是:wget-O/dev/null-q
30 * * * * /usr/bin/php '/home1/USER_NAME/public_html/twitter/index.php'