You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.2 KiB

<?php
function read_tweets(){
$fpServer = fsockopen("spitfire.initlab.org", 8124, $errno, $errstr, 30);
$fpLocal = @fopen("tweets.txt", "w");
$tweet_contents = array();
if (!$fpServer) {
echo "$errstr ($errno)\n";
}
else {
$out = "QUIT\r\n\r\n";
fwrite($fpServer, $out);
$i=0;
while (!feof($fpServer)) {
// echo fgets($fpServer, 128);
$tweet_contents[$i] = fgets($fpServer, 128);
$i++;
}
fclose($fpServer);
}
for($i=0; $i<2; $i++){
array_pop($tweet_contents);
}
array_shift($tweet_contents);
if($fpLocal) {
for ($i=0; $i<count($tweet_contents); $i++){
fwrite($fpLocal, $tweet_contents[$i]);
}
}
fclose($fpLocal);
}
function send_tweet() {
if(file_exists("FOR_SEND.TXT")) {
$fpServer = fsockopen("spitfire.initlab.org", 8124, $errno, $errstr, 30);
$tweet = file_get_contents("FOR_SEND.TXT");
if (!$fpServer) {
echo "$errstr ($errno)\n";
}
else {
usleep(1500000);
$out = "SEND " . $tweet . "\r\n";
// $out .= "QUIT\r\n\r\n";
fwrite($fpServer, $out);
usleep(1500000);
fclose($fpServer);
}
unlink("FOR_SEND.TXT");
}
}
while(42){
read_tweets();
usleep(1);
send_tweet();
sleep(30);
}
?>