Using sockets in PHP : Get articles from Usenet
Getting some articles
Now that we have the article number of the latest article, it is easy to get the latest ten articles. RFC977 says the ARTICLE command can be both used with the article number or the its Message ID.
Be careful here. The article number is different from its Message ID, as every news server will assign its own, so the article number of the same article will not be the same on two different news servers, whereas the message ID, included in the articles’s header, is unique.
<?php
$cfgLimit
= 10;
// upload last articles
$boucle=$last-$cfgLimit;
while (
$boucle <= $last) {
set_time_limit(0);
fputs($usenet_handle, "ARTICLE $bouclen");
$article="";
$tmp = fgets($usenet_handle, 4096);
if(substr($tmp,0,3) != "220") {
echo "+----------------------+n";
echo "Error on article $bouclen";
echo "+----------------------+n";
}
else {
while($tmp!=".rn") {
$tmp = fgets($usenet_handle, 4096);
$article = $article.$tmp;
}
echo "+----------------------+n";
echo "Article $bouclen";
echo "+----------------------+n";
echo "$articlen";
}
$boucle++;
}
?>
We just retrieved the ten latest articles available for this newsgroup on this server. It is also posible to get only the article’s header, thanks to the HEAD command, or only the text using the BODY command.