Using sockets: Getting Articles from newsgroups (iii)

Source: Internet
Author: User
Tags header nntp nntp server socket
Reading articles
Now that we've got the article number for the last article, it's easy to read the last 10 articles. RFC977 says the article command can use either the article number or its message ID.
Here to note that the article number is different from its message ID because each news server assigns its own article number, so the number of the same article on two different servers is not the same, and the message ID of the article is included in the header information of the article and 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, 4069);
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. = $tmp;
}

echo "+----------------------+n";
echo "Article $bouclen";
echo "+----------------------+n";
echo "$articlen";
}

$boucle + +;
}

?>

We read the last 10 articles from this newsgroup in the server. You can also read the header information of an article by using the Head command, or read the contents of the article using the Body command.

Close connection
Finally, close the socket by calling the Fclose () function to end the conversation with the NNTP server.

<?php
Close connection
Fclose ($usenet _handle);
?>
For more information about fclose (), refer to the http://www.php.net/manual/function.fclose.php

Conclusion
In the above, we saw how to open, use, and then close a socket: Connect to an NNTP server and retrieve some articles. Using post commands to publish an article is less complicated.
The next step is to write a web-based newsgroup client.
Storing these articles and indexing them with a search engine (such as http://www.htdig.org) is also very easy. In this way, you have a web-based search newsgroup program.
An example of such a program can be obtained in http://www.phpindex.com/ng/.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.