"Tweet-getter"응용 프로그램을 실행할 때마다 2 분마다 실행되는 스크립트가 있습니다. 간단히 말해서 페이스 북에 트윗을 넣습니다. 때때로 나는 딸꾹질을하고 나의 오류 검사에도 불구하고 오래된 트윗을 매 2 분마다 반복적으로 다시 게시합니다 (주기는 크론 작업으로 실행됩니다). 나는 이론적으로 여기서 무슨 일이 일어나는지를 결정하는데 도움이되는 log.txt를 가지고있다. 그러나 문제는 그것이 작업이 실행될 때마다 쓰여지지 않는다는 것이다. 여기에 코드입니다 :..PHP에서 예측할 수없는 로그 파일 작성
로그 2009은 오후 10시 41분 32초 모든 이후 # 3326415954.이 # 3526415953. 8 사용자로 업데이트라는 8 월 24 일 월요일 "의 문자열을 것입니다 그래서 이론적으로<?php
$start_time = microtime();
require_once //a library and config
$facebook = new Facebook($api_key, $secret);
get_db_conn(); //returns $conn
$hold_me = mysql_fetch_array(mysql_query("SELECT * FROM `stats`"));
$last_id_posted = $hold_me[0]; //the status # of the most recently posted tweet
$me = "mytwittername";
$ch = curl_init("http://twitter.com/statuses/friends_timeline.xml?since_id=$last_id_posted");
curl_setopt($ch, CURLOPT_USERPWD, $me.":".$pw);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xs = curl_exec($ch);
$data = new SimpleXMLElement($xs);
$latest_tweet_id = $last_id_posted;
$uid = get_uid(); //returns an array of facebookID->twittername
$user_count = count($uid);
curl_close($ch);
$total_tweets = 0;
$posted_tweets = 0;
foreach ($data->status as $tweet) {
$name = strtolower($tweet->user->screen_name);
if (array_key_exists($name, $uid)) {
$total_tweets += 1;
// $name = Twitter Name
$message = $tweet->text;
$fbid = $uid[$name];
theposting($name,$message,$fbid); //posts tweet to facebook
$this_id = $tweet->id;
if ($this_id > $latest_tweet_id) {
$latest_tweet_id = $this_id;
}
}
}
mysql_query("UPDATE stats SET lasttweet='$latest_tweet_id'");
commit_log(); //logs to a txt file how many tweets posted, how many users, execution duration, and time of execution
?>
은 0.086057 밀리 초를 툭 20 개의 트윗 중 14 개를 게시했습니다. " 윤곽. 그러나 때때로, 그것은 한 번에 두세 시간을 건너 뛸 것이며, 그 기간에 사람들의 페이스 북 페이지를 같은 트윗의 여러 복사본으로 "스팸"할 것입니다. 내 코드를 깨뜨릴 수 있다고 말할 수는 없지만 트위터의 XML은 잘못된 것입니다. 대체로 트래픽이 상대적으로 적으므로 내 서버 나 다른 서버에 과부하가 걸릴 수 있습니다. log.txt는 현재 50kb이고, 마지막에는 ~ 35kb에서 "고장"하므로 거대한 파일이 느려지지는 않습니다 ... 어떤 생각이라도 감사하겠습니다!