Use sockets: getting articles from newsgroups (3) _ PHP Tutorial

Source: Internet
Author: User
Tags nntp nntp server
Use sockets: obtain an article from a newsgroup (3 ). Since we have obtained the number of the last article, it is easy to read the last 10 articles. In RFC977, the ARTICLE command can read the ARTICLE by using the ARTICLE number.
Since we have obtained the number of the last article, it is easy to read the last 10 articles. In RFC977, the ARTICLE command can use either the ARTICLE number or its message ID.
Note that the article number is different from its message ID, because each news server assigns its own article number, therefore, the numbers of the same article on two different servers are different, and the message ID of the article is included in the header information of the article and is unique.

$ 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 )! = & Quot; 220 & quot "){
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 the newsgroup on the server ,. You can also use the HEAD command to read the header information of an article or the BODY command to read the content of the article.

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

// Close connection
Fclose ($ usenet_handle );
?>
For more information about fclose (), see http://www.php.net/manual/function.fclose.php

Conclusion
In the above article, we see how to open, use, and then close a socket: connect to an NNTP server and retrieve some articles. Using the POST command to POST articles is not complicated.
The next step is to write a WEB-based newsgroup client.
It is also very easy to index these articles with a search engine, such as a http://www.htdig.org. In this way, you have a web-based newsgroup search program.
An example of such a program can be obtained at http://www.phpindex.com/ng.

Since we have obtained the number of the last article, it is easy to read the last 10 articles. In RFC977, the ARTICLE command can use the document number...

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.